ArrayList.BinarySearch Method (Object)
Searches the entire sorted ArrayList for an element using the default comparer and returns the zero-based index of the element.
Assembly: mscorlib (in mscorlib.dll)
abstract BinarySearch : value:Object -> int override BinarySearch : value:Object -> int
The value parameter and each element of the ArrayList must implement the IComparable interface, which is used for comparisons. The elements of the ArrayList must already be sorted in increasing value according to the sort order defined by the IComparable implementation; otherwise, the result might be incorrect.
Comparing null with any type is allowed and does not generate an exception when using IComparable. When sorting, null is considered to be less than any other object.
If the ArrayList contains more than one element with the same value, the method returns only one of the occurrences, and it might return any one of the occurrences, not necessarily the first one.
If the ArrayList does not contain the specified value, the method returns a negative integer. You can apply the bitwise complement operation (~) to this negative integer to get the index of the first element that is larger than the search value. When inserting the value into the ArrayList, this index should be used as the insertion point to maintain the sort order.
This method is an O(log n) operation, where n is Count.
Available since 10
Available since 1.1