ArrayExtensions.Enumerate<T>(T[]) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Enumerates the items in the input T
array instance, as pairs of reference/index values.
This extension should be used directly within a foreach
loop:
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 T[] array);
static member Enumerate : 'T[] -> Microsoft.Toolkit.HighPerformance.Enumerables.SpanEnumerable<'T>
<Extension()>
Public Function Enumerate(Of T) (array As T()) As SpanEnumerable(Of T)
Type Parameters
- T
The type of items to enumerate.
Parameters
- array
- T[]
The source T
array to enumerate.
Returns
A wrapper type that will handle the reference/index enumeration for array
.
Remarks
The returned SpanEnumerable<T> value shouldn't be used directly: use this extension in a foreach
loop.