Mono Class Library: System.Array Overview | MembersSystem.Array.BinarySearch Method |
Searches the specified one-dimensional Array for the specified object. [Edit]
|
A int with one of the following values based on the result of the search operation.
Return Value Description The index of value in the array. value was found. The bitwise complement of the index of the first element that is larger than value. value was not found and the value of at least one element of array was greater than value. The bitwise complement of (array.GetLowerBound(0) + array.Length). value was not found, and value was greater than the value of all array elements. Note: If value is not found, the caller can take the bitwise complement of the return value to determine the index where value would be found in array if it is sorted already.[Edit]
Type Reason ArgumentException Both value and at least one element of array do not implement the IComparable interface.
-or-
value is not assignment-compatible with at least one element of array.
-or-
array.UpperBound == int.MaxValue.
[Edit]ArgumentNullException array is null. [Edit] RankException array has more than one dimension. [Edit] InvalidOperationException Both value and at least one element of array do not implement the IComparable interface. [Edit]
This version of Array.BinarySearch(Array, object) is equivalent to Array.BinarySearch(Array, object)(array, array.GetLowerBound(0), array.Length, value, null).
value is compared to each element of array using the IComparable interface of the element being compared - or of value if the element being compared does not implement the interface - until an element with a value greater than or equal to value is found. If value does not implement the IComparable interface and is compared to an element that does not implement the IComparable interface, a InvalidOperationException exception is thrown. If array is not already sorted, correct results are not guaranteed.
Note: A null reference can be compared with any type; therefore, comparisons with a null reference do not generate exceptions.[Edit]
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0