CollectionAlgorithmsBinarySearchT Method (IListT, T, IComparerT, Int32, Int32) |
Uses a binary search algorithm to locate a specific element in the sorted
IListT.
Namespace:
AGI.Foundation.Infrastructure
Assembly:
AGI.Foundation.Core (in AGI.Foundation.Core.dll) Version: 24.2.419.0 (24.2.419.0)
Syntax public static int BinarySearch<T>(
IList<T> collection,
T item,
IComparer<T> comparer,
int startIndex,
int length
)
Public Shared Function BinarySearch(Of T) (
collection As IList(Of T),
item As T,
comparer As IComparer(Of T),
startIndex As Integer,
length As Integer
) As Integer
public:
generic<typename T>
static int BinarySearch(
IList<T>^ collection,
T item,
IComparer<T>^ comparer,
int startIndex,
int length
)
static member BinarySearch :
collection : IList<'T> *
item : 'T *
comparer : IComparer<'T> *
startIndex : int *
length : int -> int
Parameters
- collection
- Type: System.Collections.GenericIListT
The collection to search. - item
- Type: T
The item to find. - comparer
- Type: System.Collections.GenericIComparerT
The IComparerT implementation to use when comparing elements. - startIndex
- Type: SystemInt32
The index of the first item to consider in the search. - length
- Type: SystemInt32
The number of items to consider in the search, starting with startIndex.
Type Parameters
- T
- The type of item in the collection.
Return Value
Type:
Int32
The zero-based index of item in the sorted IList, 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.
Remarks See Also