ImmutableArray.BinarySearch 方法

定义

重载

BinarySearch<T>(ImmutableArray<T>, T)

使用默认比较器在已排序的数组中搜索指定的元素,如果已找到,则返回该元素的从零开始的索引。Searches the sorted immutable array for a specified element using the default comparer and returns the zero-based index of the element, if it's found.

BinarySearch<T>(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.

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

在已排序的不可变数组中搜索指定的元素,如果已找到,则返回该元素的从零开始的索引。Searches a sorted immutable array for a specified element and returns the zero-based index of the element, if it's found.

BinarySearch<T>(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.

BinarySearch<T>(ImmutableArray<T>, T)

使用默认比较器在已排序的数组中搜索指定的元素,如果已找到,则返回该元素的从零开始的索引。Searches the sorted immutable array for a specified element using the default comparer and returns the zero-based index of the element, if it's found.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static int BinarySearch(System::Collections::Immutable::ImmutableArray<T> array, T value);
public static int BinarySearch<T> (this System.Collections.Immutable.ImmutableArray<T> array, T value);
static member BinarySearch : System.Collections.Immutable.ImmutableArray<'T> * 'T -> int
<Extension()>
Public Function BinarySearch(Of T) (array As ImmutableArray(Of T), value As T) As Integer

类型参数

T

数组中存储的元素的类型。The type of element stored in the array.

参数

array
ImmutableArray<T>

要搜索的已排序数组。The sorted array to search.

value
T

要搜索的对象。The object to search for.

返回

如果找到该项,则为数组中项的从零开始的索引;否则为一个负数,该负数是大于 value 的下一个元素的索引的按位求补。如果没有更大的元素,则为 Count 的按位求补。The 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.

异常

value 不实现 IComparable或搜索遇到不实现 IComparable 的元素。value does not implement IComparable or the search encounters an element that does not implement IComparable.

BinarySearch<T>(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.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static int BinarySearch(System::Collections::Immutable::ImmutableArray<T> array, T value, System::Collections::Generic::IComparer<T> ^ comparer);
public static int BinarySearch<T> (this System.Collections.Immutable.ImmutableArray<T> array, T value, System.Collections.Generic.IComparer<T> comparer);
static member BinarySearch : System.Collections.Immutable.ImmutableArray<'T> * 'T * System.Collections.Generic.IComparer<'T> -> int
<Extension()>
Public Function BinarySearch(Of T) (array As ImmutableArray(Of T), value As T, comparer As IComparer(Of T)) As Integer

类型参数

T

数组中存储的元素的类型。The type of element stored in the array.

参数

array
ImmutableArray<T>

要搜索的已排序数组。The sorted array to search.

value
T

要搜索的对象。The object to search for.

comparer
IComparer<T>

比较元素时要使用的比较器实现,或者为 null,表示使用默认比较器。The comparer implementation to use when comparing elements, or null to use the default comparer.

返回

如果找到该项,则为数组中项的从零开始的索引;否则为一个负数,该负数是大于 value 的下一个元素的索引的按位求补。如果没有更大的元素,则为 Count 的按位求补。The 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.

异常

comparer 为 null,且 value 不实现 IComparable 或搜索遇到不实现 IComparable 的元素。comparer is null and value does not implement IComparable or the search encounters an element that does not implement IComparable.

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

在已排序的不可变数组中搜索指定的元素,如果已找到,则返回该元素的从零开始的索引。Searches a sorted immutable array for a specified element and returns the zero-based index of the element, if it's found.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static int BinarySearch(System::Collections::Immutable::ImmutableArray<T> array, int index, int length, T value);
public static int BinarySearch<T> (this System.Collections.Immutable.ImmutableArray<T> array, int index, int length, T value);
static member BinarySearch : System.Collections.Immutable.ImmutableArray<'T> * int * int * 'T -> int
<Extension()>
Public Function BinarySearch(Of T) (array As ImmutableArray(Of T), index As Integer, length As Integer, value As T) As Integer

类型参数

T

数组中存储的元素的类型。The type of element stored in the array.

参数

array
ImmutableArray<T>

要搜索的已排序数组。The sorted array to search.

index
Int32

要搜索的范围的起始索引。The starting index of the range to search.

length
Int32

要搜索的范围的长度。The length of the range to search.

value
T

要搜索的对象。The object to search for.

返回

如果找到该项,则为数组中项的从零开始的索引;否则为一个负数,该负数是大于 value 的下一个元素的索引的按位求补。如果没有更大的元素,则为 Count 的按位求补。The 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.

异常

value 不实现 IComparable或搜索遇到不实现 IComparable 的元素。value does not implement IComparable or the search encounters an element that does not implement IComparable.

indexlength 未在 array 中指定有效范围。index and length do not specify a valid range in array.

index 小于 array 的下限。index is less than the lower bound of array.

-or-

length 小于零。length is less than zero.

BinarySearch<T>(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.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static int BinarySearch(System::Collections::Immutable::ImmutableArray<T> array, int index, int length, T value, System::Collections::Generic::IComparer<T> ^ comparer);
public static int BinarySearch<T> (this System.Collections.Immutable.ImmutableArray<T> array, int index, int length, T value, System.Collections.Generic.IComparer<T> comparer);
static member BinarySearch : System.Collections.Immutable.ImmutableArray<'T> * int * int * 'T * System.Collections.Generic.IComparer<'T> -> int
<Extension()>
Public Function BinarySearch(Of T) (array As ImmutableArray(Of T), index As Integer, length As Integer, value As T, comparer As IComparer(Of T)) As Integer

类型参数

T

数组中存储的元素的类型。The type of element stored in the array.

参数

array
ImmutableArray<T>

要搜索的已排序数组。The sorted array to search.

index
Int32

要搜索的范围的起始索引。The starting index of the range to search.

length
Int32

要搜索的范围的长度。The length of the range to search.

value
T

要搜索的对象。The object to search for.

comparer
IComparer<T>

比较元素的相等性时要使用的比较器,或者为 null,表示使用默认比较器。The comparer to use when comparing elements for equality or null to use the default comparer.

返回

如果找到该项,则为数组中项的从零开始的索引;否则为一个负数,该负数是大于 value 的下一个元素的索引的按位求补。如果没有更大的元素,则为 Count 的按位求补。The 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.

异常

comparer 为 null,且 value 不实现 IComparable 或搜索遇到不实现 IComparable 的元素。comparer is null and value does not implement IComparable or the search encounters an element that does not implement IComparable.

indexlength 未在 array 中指定有效范围。index and length do not specify a valid range in array.

-or-

comparernull,并且 value 的类型与 array 的元素不兼容。comparer is null, and value is of a type that is not compatible with the elements of array.

index 小于 array 的下限。index is less than the lower bound of array.

-or-

length 小于零。length is less than zero.

适用于