Mono Class Library: System.Array Overview | MembersSystem.Array.BinarySearch Method |
Searches the specified section of the specified one-dimensional Array for the specified value. [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 at least one array element in the range of index to index + length - 1 was greater than value. The bitwise complement of (index + length). value was not found, and value was greater than all array elements in the range of index to index + length- 1. Note: If value is not found, the caller can take the bitwise complement of the return value to determine the index of the array where value would be found in the range of index to index + length - 1 if array is already sorted.[Edit]
Type Reason ArgumentNullException array is null . [Edit] RankException array has more than one dimension. [Edit] ArgumentOutOfRangeException index < array.GetLowerBound(0).
-or-
length < 0.
[Edit]ArgumentException index and length do not specify a valid range in array (i.e. index + length > array.GetLowerBound(0) + array.Length).
-or-
array.UpperBound == int.MaxValue.
[Edit]InvalidOperationException Either value or at least one element of array does 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