ImmutableArray.BinarySearch 方法

定義

多載

名稱 Description
BinarySearch<T>(ImmutableArray<T>, T)

使用預設比較器搜尋已排序的不可變陣列,尋找指定元素,若找到該元素,則回傳該元素的零索引。

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

在已排序的不可變陣列中搜尋指定元素,若找到該元素,則回傳該元素的零為基礎索引。

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

在已排序的不可變陣列中搜尋指定元素,若找到該元素,則回傳該元素的零為基礎索引。

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

在已排序的不可變陣列中搜尋指定元素,並回傳該元素的零基索引。

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

使用預設比較器搜尋已排序的不可變陣列,尋找指定元素,若找到該元素,則回傳該元素的零索引。

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

陣列中儲存的元素類型。

參數

array
ImmutableArray<T>

排序陣列用來搜尋。

value
T

要搜尋的物件。

傳回

若找到該項目,則為陣列中以零為基礎的索引;否則,則為負數,即下一個大於 value 元素的指標的位元補數;若無較大元素,則為的 Count位元補數。

例外狀況

value 未實作 IComparable 或搜尋遇到未實作 IComparable元素。

適用於

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

在已排序的不可變陣列中搜尋指定元素,若找到該元素,則回傳該元素的零為基礎索引。

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

陣列中儲存的元素類型。

參數

array
ImmutableArray<T>

排序陣列用來搜尋。

value
T

要搜尋的物件。

comparer
IComparer<T>

比較器實作用於比較元素,或 null 使用預設比較器。

傳回

若找到該項目,則為陣列中以零為基礎的索引;否則,則為負數,即下一個大於 value 元素的指標的位元補數;若無較大元素,則為的 Count位元補數。

例外狀況

comparer 是空 value 且不實作 IComparable ,或搜尋遇到不實作 IComparable元素。

適用於

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

在已排序的不可變陣列中搜尋指定元素,若找到該元素,則回傳該元素的零為基礎索引。

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

陣列中儲存的元素類型。

參數

array
ImmutableArray<T>

排序陣列用來搜尋。

index
Int32

要搜尋之範圍的起始索引。

length
Int32

要搜尋的範圍長度。

value
T

要搜尋的物件。

傳回

若找到該項目,則為陣列中以零為基礎的索引;否則,則為負數,即下一個大於 value 元素的指標的位元補數;若無較大元素,則為的 Count位元補數。

例外狀況

value 未實作 IComparable 或搜尋遇到未實作 IComparable元素。

indexlength不指定有效範圍。array

index 小於 的 array下界。

-或-

length 小於零。

適用於

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

在已排序的不可變陣列中搜尋指定元素,並回傳該元素的零基索引。

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

陣列中儲存的元素類型。

參數

array
ImmutableArray<T>

排序陣列用來搜尋。

index
Int32

要搜尋之範圍的起始索引。

length
Int32

要搜尋的範圍長度。

value
T

要搜尋的物件。

comparer
IComparer<T>

比較器在比較元素以求相等 null 時,或使用預設的比較器。

傳回

若找到該項目,則為陣列中以零為基礎的索引;否則,則為負數,即下一個大於 value 元素的指標的位元補數;若無較大元素,則為的 Count位元補數。

例外狀況

comparer 是空 value 且不實作 IComparable ,或搜尋遇到不實作 IComparable元素。

indexlength不指定有效範圍。array

-或-

comparernull,且 value 的類型與 的 array元素不相容。

index 小於 的 array下界。

-或-

length 小於零。

適用於