ImmutableArray::BinarySearch<T> Method (ImmutableArray<T>, Int32, Int32, T, IComparer<T>^)
Searches a sorted immutable array for a specified element and returns the zero-based index of the element.
Assembly: System.Collections.Immutable (in System.Collections.Immutable.dll)
public: generic<typename T> [ExtensionAttribute] static int BinarySearch( ImmutableArray<T> array, int index, int length, T value, IComparer<T>^ comparer )
Parameters
- array
-
Type:
System.Collections.Immutable::ImmutableArray<T>
The sorted array to search.
- index
-
Type:
System::Int32
The starting index of the range to search.
- length
-
Type:
System::Int32
The length of the range to search.
- value
-
Type:
T
The object to search for.
- comparer
-
Type:
System.Collections.Generic::IComparer<T>^
The comparer to use when comparing elements for equality 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. |