Click or drag to resize
ListTBinarySearch Method (Int32, Int32, T, IComparerT)
Searches a range of elements in the sorted ListT for an element using the specified comparer and returns the zero-based index of the element.

Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax
C#
public int BinarySearch(
	int index,
	int count,
	T item,
	IComparer<T> comparer
)

Parameters

index
Type: SystemInt32
The zero-based starting index of the range to search.
count
Type: SystemInt32
The length of the range to search.
item
Type: T
The object to locate. The value can be null for reference types.
comparer
Type: System.Collections.GenericIComparerT
The IComparerT implementation to use when comparing elements, or null to use the default comparer Default.

Return Value

Type: Int32
The zero-based index of item in the sorted ListT, 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.
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionindex is less than 0.-or-count is less than 0.
ArgumentExceptionindex and count do not denote a valid range in the ListT.
InvalidOperationExceptioncomparer is null, and the default comparer Default cannot find an implementation of the IComparableT generic interface or the IComparable interface for type T.
See Also