Array.BinarySearch Method (Array, Int32, Int32, Object, IComparer)
Searches a specified range within a one-dimensional sorted array for a specified value, using the specified IComparer interface.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
public static int BinarySearch (
Array array,
int index,
int length,
Object value,
IComparer comparer
)
Parameters
- array
The one-dimensional array containing the range you want to search. - index
The starting index number of the range you want to search. - length
The length of the range you want to search. - value
The object you want to search for in the range. - comparer
The IComparer implementation you want to use when comparing objects. If this parameter is null, the Array.BinarySearch method uses the IComparable implementation of each object in the search range.
Return Value
The index number of the specified value in the specified array, if that value is found in the array.
-or-
A negative number, which is the bitwise complement of the index number of the first object that is larger than the specified value, if that value is not found and it is less than at least one of the objects in the array.
-or-
A negative number, which is the bitwise complement of the index number of the last object in the array plus 1, if the specified value is not found and it is greater than at least one of the objects in the array.
Version Information
Available in the .NET Micro Framework versions 2.0, 2.5, 3.0, 4.0, 4.1, and 4.2.