MemoryExtensions.BinarySearch Method

Definition

Overloads

BinarySearch<T,TComparable>(Span<T>, TComparable)

使用指定的 TComparable 泛型类型,在整个已排序的 Span<T> 中搜索值。Searches an entire sorted Span<T> for a value using the specified TComparable generic type.

BinarySearch<T,TComparable>(ReadOnlySpan<T>, TComparable)

使用指定的 TComparable 泛型类型,在整个已排序的 ReadOnlySpan<T> 中搜索值。Searches an entire sorted ReadOnlySpan<T> for a value using the specified TComparable generic type.

BinarySearch<T,TComparer>(ReadOnlySpan<T>, T, TComparer)

使用指定的 TComparer 泛型类型,在整个已排序的 ReadOnlySpan<T> 中搜索指定值。Searches an entire sorted ReadOnlySpan<T> for a specified value using the specified TComparer generic type.

BinarySearch<T,TComparer>(Span<T>, T, TComparer)

使用指定的 TComparer 泛型类型,在整个已排序的 Span<T> 中搜索指定值。Searches an entire sorted Span<T> for a specified value using the specified TComparer generic type.

BinarySearch<T>(ReadOnlySpan<T>, IComparable<T>)

使用指定的 IComparable<T> 泛型接口,在整个已排序的 ReadOnlySpan<T> 中搜索值。Searches an entire sorted ReadOnlySpan<T> for a value using the specified IComparable<T> generic interface.

BinarySearch<T>(Span<T>, IComparable<T>)

使用指定的 IComparable<T> 泛型接口,在整个已排序的 Span<T> 中搜索值。Searches an entire sorted Span<T> for a value using the specified IComparable<T> generic interface.

BinarySearch<T,TComparable>(Span<T>, TComparable)

使用指定的 TComparable 泛型类型,在整个已排序的 Span<T> 中搜索值。Searches an entire sorted Span<T> for a value using the specified TComparable generic type.

public:
generic <typename T, typename TComparable>
 where TComparable : IComparable<T>[System::Runtime::CompilerServices::Extension]
 static int BinarySearch(Span<T> span, TComparable comparable);
public static int BinarySearch<T,TComparable> (this Span<T> span, TComparable comparable) where TComparable : IComparable<T>;
static member BinarySearch : Span<'T> * 'Comparable -> int (requires 'Comparable :> IComparable<'T>)
<Extension()>
Public Function BinarySearch(Of T, TComparable) (span As Span(Of T), comparable As TComparable) As Integer

Type Parameters

T

跨度的元素类型。The element type of the span.

TComparable

IComparable<T>的特定类型。The specific type of IComparable<T>.

Parameters

span
Span<T>

要搜索的已排序 Span<T>The sorted Span<T> to search.

comparable
TComparable

比较时要使用的 TComparableThe TComparable to use when comparing.

Returns

Int32

如果找到 comparable,则为已排序的 spancomparable 的从零开始的索引;否则为一个负数,该负数是大于 comparable 的下一个元素的索引的按位求补。如果没有更大的元素,则为 Length 的按位求补。The zero-based index of comparable in the sorted span, if comparable is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than comparable or, if there is no larger element, the bitwise complement of Length.

Exceptions

comparablenullcomparable is null.

BinarySearch<T,TComparable>(ReadOnlySpan<T>, TComparable)

使用指定的 TComparable 泛型类型,在整个已排序的 ReadOnlySpan<T> 中搜索值。Searches an entire sorted ReadOnlySpan<T> for a value using the specified TComparable generic type.

public:
generic <typename T, typename TComparable>
 where TComparable : IComparable<T>[System::Runtime::CompilerServices::Extension]
 static int BinarySearch(ReadOnlySpan<T> span, TComparable comparable);
public static int BinarySearch<T,TComparable> (this ReadOnlySpan<T> span, TComparable comparable) where TComparable : IComparable<T>;
static member BinarySearch : ReadOnlySpan<'T> * 'Comparable -> int (requires 'Comparable :> IComparable<'T>)
<Extension()>
Public Function BinarySearch(Of T, TComparable) (span As ReadOnlySpan(Of T), comparable As TComparable) As Integer

Type Parameters

T

跨度的元素类型。The element type of the span.

TComparable

IComparable<T>的特定类型。The specific type of IComparable<T>.

Parameters

span
ReadOnlySpan<T>

要搜索的已排序 ReadOnlySpan<T>The sorted ReadOnlySpan<T> to search.

comparable
TComparable

比较时要使用的 TComparableThe TComparable to use when comparing.

Returns

Int32

如果找到 comparable,则为已排序的 spancomparable 的从零开始的索引;否则为一个负数,该负数是大于 comparable 的下一个元素的索引的按位求补。如果没有更大的元素,则为 Length 的按位求补。The zero-based index of comparable in the sorted span, if comparable is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than comparable or, if there is no larger element, the bitwise complement of Length.

Exceptions

comparablenullcomparable is null.

BinarySearch<T,TComparer>(ReadOnlySpan<T>, T, TComparer)

使用指定的 TComparer 泛型类型,在整个已排序的 ReadOnlySpan<T> 中搜索指定值。Searches an entire sorted ReadOnlySpan<T> for a specified value using the specified TComparer generic type.

public:
generic <typename T, typename TComparer>
 where TComparer : System::Collections::Generic::IComparer<T>[System::Runtime::CompilerServices::Extension]
 static int BinarySearch(ReadOnlySpan<T> span, T value, TComparer comparer);
public static int BinarySearch<T,TComparer> (this ReadOnlySpan<T> span, T value, TComparer comparer) where TComparer : System.Collections.Generic.IComparer<T>;
static member BinarySearch : ReadOnlySpan<'T> * 'T * 'Comparer -> int (requires 'Comparer :> System.Collections.Generic.IComparer<'T>)
<Extension()>
Public Function BinarySearch(Of T, TComparer) (span As ReadOnlySpan(Of T), value As T, comparer As TComparer) As Integer

Type Parameters

T

跨度的元素类型。The element type of the span.

TComparer

IComparer<T>的特定类型。The specific type of IComparer<T>.

Parameters

span
ReadOnlySpan<T>

要搜索的已排序 ReadOnlySpan<T>The sorted ReadOnlySpan<T> to search.

value
T

要定位的对象。The object to locate. 对于引用类型,该值可以为 nullThe value can be null for reference types.

comparer
TComparer

比较时要使用的 TComparerThe TComparer to use when comparing.

Returns

Int32

如果找到 value,则为已排序的 spanvalue 的从零开始的索引;否则为一个负数,该负数是大于 value 的下一个元素的索引的按位求补。如果没有更大的元素,则为 Length 的按位求补。The zero-based index of value in the sorted span, if value 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 Length.

Exceptions

comparernullcomparer is null.

BinarySearch<T,TComparer>(Span<T>, T, TComparer)

使用指定的 TComparer 泛型类型,在整个已排序的 Span<T> 中搜索指定值。Searches an entire sorted Span<T> for a specified value using the specified TComparer generic type.

public:
generic <typename T, typename TComparer>
 where TComparer : System::Collections::Generic::IComparer<T>[System::Runtime::CompilerServices::Extension]
 static int BinarySearch(Span<T> span, T value, TComparer comparer);
public static int BinarySearch<T,TComparer> (this Span<T> span, T value, TComparer comparer) where TComparer : System.Collections.Generic.IComparer<T>;
static member BinarySearch : Span<'T> * 'T * 'Comparer -> int (requires 'Comparer :> System.Collections.Generic.IComparer<'T>)
<Extension()>
Public Function BinarySearch(Of T, TComparer) (span As Span(Of T), value As T, comparer As TComparer) As Integer

Type Parameters

T

跨度的元素类型。The element type of the span.

TComparer

IComparer<T>的特定类型。The specific type of IComparer<T>.

Parameters

span
Span<T>

要搜索的已排序 Span<T>The sorted Span<T> to search.

value
T

要定位的对象。The object to locate. 对于引用类型,该值可以为 nullThe value can be null for reference types.

comparer
TComparer

比较时要使用的 TComparerThe TComparer to use when comparing.

Returns

Int32

如果找到 value,则为已排序的 spanvalue 的从零开始的索引;否则为一个负数,该负数是大于 value 的下一个元素的索引的按位求补。如果没有更大的元素,则为 Length 的按位求补。The zero-based index of value in the sorted span, if value 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 Length.

Exceptions

comparernullcomparer is null.

BinarySearch<T>(ReadOnlySpan<T>, IComparable<T>)

使用指定的 IComparable<T> 泛型接口,在整个已排序的 ReadOnlySpan<T> 中搜索值。Searches an entire sorted ReadOnlySpan<T> for a value using the specified IComparable<T> generic interface.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static int BinarySearch(ReadOnlySpan<T> span, IComparable<T> ^ comparable);
public static int BinarySearch<T> (this ReadOnlySpan<T> span, IComparable<T> comparable);
static member BinarySearch : ReadOnlySpan<'T> * IComparable<'T> -> int
<Extension()>
Public Function BinarySearch(Of T) (span As ReadOnlySpan(Of T), comparable As IComparable(Of T)) As Integer

Type Parameters

T

跨度的元素类型。The element type of the span.

Parameters

span
ReadOnlySpan<T>

要搜索的已排序 ReadOnlySpan<T>The sorted ReadOnlySpan<T> to search.

comparable
IComparable<T>

比较时要使用的 IComparable<T>The IComparable<T> to use when comparing.

Returns

Int32

如果找到 comparable,则为已排序的 spancomparable 的从零开始的索引;否则为一个负数,该负数是大于 comparable 的下一个元素的索引的按位求补。如果没有更大的元素,则为 Length 的按位求补。The zero-based index of comparable in the sorted span, if comparable is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than comparable or, if there is no larger element, the bitwise complement of Length.

Exceptions

comparablenullcomparable is null.

BinarySearch<T>(Span<T>, IComparable<T>)

使用指定的 IComparable<T> 泛型接口,在整个已排序的 Span<T> 中搜索值。Searches an entire sorted Span<T> for a value using the specified IComparable<T> generic interface.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static int BinarySearch(Span<T> span, IComparable<T> ^ comparable);
public static int BinarySearch<T> (this Span<T> span, IComparable<T> comparable);
static member BinarySearch : Span<'T> * IComparable<'T> -> int
<Extension()>
Public Function BinarySearch(Of T) (span As Span(Of T), comparable As IComparable(Of T)) As Integer

Type Parameters

T

跨度的元素类型。The element type of the span.

Parameters

span
Span<T>

要搜索的已排序 Span<T>The sorted Span<T> to search.

comparable
IComparable<T>

比较时要使用的 IComparable<T>The IComparable<T> to use when comparing.

Returns

Int32

如果找到 comparable,则为已排序的 spancomparable 的从零开始的索引;否则为一个负数,该负数是大于 comparable 的下一个元素的索引的按位求补。如果没有更大的元素,则为 Length 的按位求补。The zero-based index of comparable in the sorted span, if comparable is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than comparable or, if there is no larger element, the bitwise complement of Length.

Exceptions

comparablenullcomparable is null.

Applies to