Created
July 14, 2022 11:18
-
-
Save teoadal/ea9c8926e6a942d46b96fe9a1faa8e22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ref struct ArrayEnumerator<T> | |
where T: struct | |
{ | |
private int _index; | |
private readonly int _length; | |
private readonly T[] _array; | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public ArrayEnumerator(T[] array) | |
{ | |
_index = 0; | |
_array = array; | |
_length = _array.Length; | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public bool MoveNext() => ++_index < _length; | |
public readonly ref T Current | |
{ | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
get => ref _array[_index]; | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public readonly ArrayEnumerator<T> GetEnumerator() => this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment