Module Module1
Sub Main()
Dim intArray As Array = Array.CreateInstance(GetType(Int32), 5)
intArray.SetValue(12, 0)
intArray.SetValue(11, 1)
intArray.SetValue(27, 2)
intArray.SetValue(73, 3)
intArray.SetValue(32, 4)
Array.Sort(intArray)
PrintArray(intArray)
Dim o As Object = 27
FindObject(intArray, o)
o = 114
FindObject(intArray, o)
End Sub
Public Sub PrintArray(arr As Array)
Dim cols As Integer = arr.GetLength(arr.Rank - 1)
For Each o As Object In arr
Console.Write(" {0}", o)
Next o
Console.WriteLine()
End Sub
Public Sub FindObject(arr As Array, o As Object)
Dim index As Integer = Array.BinarySearch(arr, o)
If index < 0 Then
Console.WriteLine("Object: {0} not found", o)
Else
Console.WriteLine("Object found: {0} at index {1}", o, index)
End If
End Sub
End Module
' run:
'
' 11 12 27 32 73
' Object found: 27 at index 2
' Object : 114 Not found