ImmutableArray::BinarySearch<T> Method (ImmutableArray<T>, T, IComparer<T>^)
Searches a sorted immutable array for a specified element and returns the zero-based index of the element, if it’s found.
Assembly: System.Collections.Immutable (in System.Collections.Immutable.dll)
public: generic<typename T> [ExtensionAttribute] static int BinarySearch( ImmutableArray<T> array, T value, IComparer<T>^ comparer )
Parameters
- array
-
Type:
System.Collections.Immutable::ImmutableArray<T>
The sorted array to search.
- value
-
Type:
T
The object to search for.
- comparer
-
Type:
System.Collections.Generic::IComparer<T>^
The comparer implementation to use when comparing elements, or null to use the default comparer.
Return Value
Type: System::Int32The zero-based index of the item in the array, if item is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than value or, if there is no larger element, the bitwise complement of Count.
Type Parameters
- T
The type of element stored in the array.
| Exception | Condition |
|---|---|
| InvalidOperationException | comparer is null and value does not implement IComparable or the search encounters an element that does not implement IComparable. |
Show: