Editar

Compartilhar via


StringExtensions.Enumerate(String) Method

Definition

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

string text = "Hello, world!";

foreach (var item in text.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 Microsoft.Toolkit.HighPerformance.Enumerables.ReadOnlySpanEnumerable<char> Enumerate (this string text);
static member Enumerate : string -> Microsoft.Toolkit.HighPerformance.Enumerables.ReadOnlySpanEnumerable<char>
<Extension()>
Public Function Enumerate (text As String) As ReadOnlySpanEnumerable(Of Char)

Parameters

text
String

The source String to enumerate.

Returns

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

Remarks

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

Applies to