Sort, Reverse, and BinarySearch

    Sub Main()

        Dim Ag() As Integer = {20356, 75834, 24566, 86378, 35624, 35678, 91124, 90210, 10140, 90210, 56715, 70328, 28643, 33775, 88488, 22222}
        'This is our pretend array.
        'I filled it with zip codes to illustrate, sorting, binary search.
        'Can you find your zip code in there.
        'Can you find mine?

        PrintArray(Ag)
        'Display the elements of this array to the console.

        Array.Sort(Ag)
        'Now, the numbers will be sorted within the array.
        'You will see the changes once we

        PrintArray(Ag)
        'Print the array again.
        'This will be the sorted version of the array.

        'Now if you want to sort the array in descending order, you might do something like this.
        Array.Reverse(Ag)

        'And now the array is in descending order.
        PrintArray(Ag)

        'Return the array to ascending order.
        Array.Reverse(Ag)

        'Suppose I wanted to find the area code 90210.
        'Note that there are two 90210s in the array.
        'I can find the first one using .IndexOf
        Console.WriteLine("The first 90210 appears at {0}.", Array.IndexOf(Ag, 90210))

        'The last one can be found with LastIndexOf.
        Console.WriteLine("The last 90210 appears at {0}.", Array.LastIndexOf(Ag, 90210))

        'Searching for an element in a sorted array is fairly silly for IndexOf and LastIndexOf.
        'We can use BinarySearch on sorted arrays to search for something quickly.
        'It does not work for unsorted arrays, but is very handy on large array.
        Console.WriteLine("35624 appears at {0}.", Array.BinarySearch(Ag, 35624))
        'Note that BinarySearch does not work on arrays sorted in descending order.

        'Another plus to BinarySearch is that, if you don't specify a number that is 
        'the list of numbers that is already in the array,
        'it will let you figure out what numbers it lies between.
        'The return value will be negative.
        Dim Loc As Integer = Array.BinarySearch(Ag, 40000)

        If Loc < 0 Then  'The number does not occur in the array.
            Console.WriteLine("The number 40000 does not appear in the array, but would go between element {0} and {1}, namely {2} and {3}", _
             -1 + Not Loc, Not Loc, Ag(-1 + Not Loc), Ag(Not Loc))
            'The documentation clearly states that if the value does not exist, the place that it would be in is inverted with Not.
        End If

        Console.ReadLine()
    End Sub

    Sub PrintArray(ByVal A() As Integer)
        For LV As Integer = 0 To A.GetUpperBound(0)
            Console.Write(A(LV).ToString() & " ")
        Next
        Console.WriteLine()
    End Sub
The console displays:
20356 75834 24566 86378 35624 35678 91124 90210 10140 90210 56715 70328 28643 33775 88488 22222
10140 20356 22222 24566 28643 33775 35624 35678 56715 70328 75834 86378 88488 90210 90210 91124
91124 90210 90210 88488 86378 75834 70328 56715 35678 35624 33775 28643 24566 22222 20356 10140
The first 90210 appears at 13.
The last 90210 appears at 14.
35624 appears at 6.
The number 40000 does not appear in the array, but would go between element 7 and 8, namely 35678 and 56715