Editar

Compartir vía


ImmutableList<T>.BinarySearch Method

Definition

Overloads

BinarySearch(T)

Searches the entire sorted list for an element using the default comparer and returns the zero-based index of the element.

BinarySearch(T, IComparer<T>)

Searches the entire sorted list for an element using the specified comparer and returns the zero-based index of the element.

BinarySearch(Int32, Int32, T, IComparer<T>)

Searches a range of elements in the sorted list for an element using the specified comparer and returns the zero-based index of the element.

BinarySearch(T)

Source:
ImmutableList_1.cs
Source:
ImmutableList_1.cs
Source:
ImmutableList_1.cs

Searches the entire sorted list for an element using the default comparer and returns the zero-based index of the element.

public:
 virtual int BinarySearch(T item);
public:
 int BinarySearch(T item);
public int BinarySearch (T item);
abstract member BinarySearch : 'T -> int
override this.BinarySearch : 'T -> int
member this.BinarySearch : 'T -> int
Public Function BinarySearch (item As T) As Integer

Parameters

item
T

The object to locate. The value can be null for reference types.

Returns

The zero-based index of item in the sorted List, 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

The default comparer cannot find a comparer implementation of the for type T.

Applies to

BinarySearch(T, IComparer<T>)

Source:
ImmutableList_1.cs
Source:
ImmutableList_1.cs
Source:
ImmutableList_1.cs

Searches the entire sorted list for an element using the specified comparer and returns the zero-based index of the element.

public:
 virtual int BinarySearch(T item, System::Collections::Generic::IComparer<T> ^ comparer);
public:
 int BinarySearch(T item, System::Collections::Generic::IComparer<T> ^ comparer);
public int BinarySearch (T item, System.Collections.Generic.IComparer<T> comparer);
public int BinarySearch (T item, System.Collections.Generic.IComparer<T>? comparer);
abstract member BinarySearch : 'T * System.Collections.Generic.IComparer<'T> -> int
override this.BinarySearch : 'T * System.Collections.Generic.IComparer<'T> -> int
member this.BinarySearch : 'T * System.Collections.Generic.IComparer<'T> -> int
Public Function BinarySearch (item As T, comparer As IComparer(Of T)) As Integer

Parameters

item
T

The object to locate. The value can be null for reference types.

comparer
IComparer<T>

The comparer implementation to use when comparing elements or null to use the default comparer.

Returns

The zero-based index of item in the sorted List, 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

comparer is null, and the default comparer cannot find an comparer implementation for type T.

Applies to

BinarySearch(Int32, Int32, T, IComparer<T>)

Source:
ImmutableList_1.cs
Source:
ImmutableList_1.cs
Source:
ImmutableList_1.cs

Searches a range of elements in the sorted list for an element using the specified comparer and returns the zero-based index of the element.

public:
 virtual int BinarySearch(int index, int count, T item, System::Collections::Generic::IComparer<T> ^ comparer);
public:
 int BinarySearch(int index, int count, T item, System::Collections::Generic::IComparer<T> ^ comparer);
public int BinarySearch (int index, int count, T item, System.Collections.Generic.IComparer<T> comparer);
public int BinarySearch (int index, int count, T item, System.Collections.Generic.IComparer<T>? comparer);
abstract member BinarySearch : int * int * 'T * System.Collections.Generic.IComparer<'T> -> int
override this.BinarySearch : int * int * 'T * System.Collections.Generic.IComparer<'T> -> int
member this.BinarySearch : int * int * 'T * System.Collections.Generic.IComparer<'T> -> int
Public Function BinarySearch (index As Integer, count As Integer, item As T, comparer As IComparer(Of T)) As Integer

Parameters

index
Int32

The zero-based starting index of the range to search.

count
Int32

The length of the range to search.

item
T

The object to locate. The value can be null for reference types.

comparer
IComparer<T>

The comparer implementation to use when comparing elements, or null to use the default comparer.

Returns

The zero-based index of item in the sorted list, 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

index is less than 0 or count is less than 0.

index and count do not denote a valid range in the list.

comparer is null, and the default comparer cannot find an comparer implementation for type T.

Applies to