Edytuj

Udostępnij za pośrednictwem


SpanExtensions.Enumerate<T>(Span<T>) Method

Definition

Enumerates the items in the input Span<T> instance, as pairs of reference/index values. This extension should be used directly within a foreach loop:

Span<int> numbers = new[] { 1, 2, 3, 4, 5, 6, 7 };

foreach (var item in numbers.Enumerate())
{
    // Access the index and value of each item here...
    int index = item.Index;
    ref int value = ref item.Value;
}

The compiler will take care of properly setting up the foreach loop with the type returned from this method.

public static Microsoft.Toolkit.HighPerformance.Enumerables.SpanEnumerable<T> Enumerate<T> (this Span<T> span);
static member Enumerate : Span<'T> -> Microsoft.Toolkit.HighPerformance.Enumerables.SpanEnumerable<'T>
<Extension()>
Public Function Enumerate(Of T) (span As Span(Of T)) As SpanEnumerable(Of T)

Type Parameters

T

The type of items to enumerate.

Parameters

span
Span<T>

The source Span<T> to enumerate.

Returns

A wrapper type that will handle the reference/index enumeration for span.

Remarks

The returned SpanEnumerable<T> value shouldn't be used directly: use this extension in a foreach loop.

Applies to