GenericExtensionsBinarySearchT Method (IListT, T, IComparerT) |
Searches the entire sorted
IListT for an element using the provided
comparer and returns the zero-based index of the element.
If the key is not found, a negative number is returned,
which can be intepreted as the bitwise complement
of the interval of indices that the key is in between, i.e.
list[interval-1] < key < list[interval]
Namespace:
DHI.Mike1D.Generic
Assembly:
DHI.Mike1D.Generic (in DHI.Mike1D.Generic.dll) Version: 16.0.0.0 (11.1.1.1111)
Syntax public static int BinarySearch<T>(
this IList<T> list,
T key,
IComparer<T> comparer
)
Parameters
- list
- Type: System.Collections.GenericIListT
List to search in - key
- Type: T
The key to locate. The value can be null for reference types. - comparer
- Type: System.Collections.GenericIComparerT
The IComparerT implementation to use when comparing elements.
Type Parameters
- T
- The type of the objects in the list
Return Value
Type:
Int32The zero-based index of item in the sorted
IListT, if item is found;
otherwise, a negative number that is the bitwise complement
of the index of the next element that is larger than item or,
if there is no larger element, the bitwise complement of Count.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type
IListT. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
See Also