Algorithms..::..BinarySearch<(Of <(<'T>)>)> Method (IList<(Of <(<'T>)>)>, T, Comparison<(Of <(<'T>)>)>, Int32%)
Searches a sorted list for an item via binary search. The list must be sorted
by the ordering in the passed Comparison<T> delegate.
Namespace:
Wintellect.PowerCollections
Assembly:
PowerCollections (in PowerCollections.dll)
Syntax
public static int BinarySearch<T>( IList<T> list, T item, Comparison<T> comparison, out int index ) where T : IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>
Public Shared Function BinarySearch(Of T As {IComparable(Of T), IComparable(Of T), IComparable(Of T), IComparable(Of T), IComparable(Of T), IComparable(Of T), IComparable(Of T), IComparable(Of T), IComparable(Of T), IComparable(Of T), IComparable(Of T), IComparable(Of T), IComparable(Of T), IComparable(Of T)}) ( _ list As IList(Of T), _ item As T, _ comparison As Comparison(Of T), _ <OutAttribute> ByRef index As Integer _ ) As Integer
public: generic<typename T> where T : IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T>, IComparable<T> static int^ BinarySearch( IList<T>^ list, T item, Comparison<T>^ comparison, [OutAttribute] int^% index )
Type Parameters
- T
Parameters
- list
- Type: IList<(Of <(<'T>)>)>
The sorted list to search.
- item
- Type: T
The item to search for.
- comparison
- Type: Comparison<(Of <(<'T>)>)>
The comparison delegate used to sort the list.
- index
- Type: Int32%
Returns the first index at which the item can be found. If the return value is zero, indicating that item was not present in the list, then this returns the index at which item could be inserted to maintain the sorted order of the list.