Modifica

Condividi tramite


ReadOnlySpanExtensions.Enumerate<T>(ReadOnlySpan<T>) Method

Definition

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

ReadOnlySpan<string> words = new[] { "Hello", ", ", "world", "!" };

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

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

public static CommunityToolkit.HighPerformance.Enumerables.ReadOnlySpanEnumerable<T> Enumerate<T> (this ReadOnlySpan<T> span);
static member Enumerate : ReadOnlySpan<'T> -> CommunityToolkit.HighPerformance.Enumerables.ReadOnlySpanEnumerable<'T>
<Extension()>
Public Function Enumerate(Of T) (span As ReadOnlySpan(Of T)) As ReadOnlySpanEnumerable(Of T)

Type Parameters

T

The type of items to enumerate.

Parameters

span
ReadOnlySpan<T>

The source ReadOnlySpan<T> to enumerate.

Returns

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

Remarks

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

Applies to