0
Dim myArray() As Integer = {a, b, c, d, f}

    Dim largest As Integer = Integer.MinValue
    Dim smallest As Integer = Integer.MaxValue

    For Each element As Integer In myArray
        largest = Math.Max(largest, element)
        smallest = Math.Min(smallest, element)
        'myArray(largest).Remove() 
    '(this part have error, as it stated that is not part of array statement)
    Next

    lblmax.Text = largest
    lblMin.Text = smallest

Based on the code above i would like to remove the largest and smallest element from the array list and then put it into a new array list, is it possible?
if yes please help out, thanks.

Edited by pyTony: fixed formatting

3
Contributors
3
Replies
6
Views
6 Years
Discussion Span
Last Post by sandeepparekh9
0

you need to pass the index of array element to remove. and in loop if u do it u will get error saying index out side the bounds of array, as element is deleted.

0

you can do something like this:

Dim myArray() As Integer = {1, 4, 7, 9, 2, 3}

        Dim max As Integer = 0
        Dim min As Integer = Integer.MaxValue

        For Each i As Integer In myArray
            If i > max Then
                max = i
            End If

            If i < min Then
                min = i
            End If
        Next

        Label1.Text = "Max : " & max & " Min : " & min

        Dim minmaxArray() As Integer = {max, min}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.