Skip to content

Instantly share code, notes, and snippets.

@teoadal
Created July 14, 2022 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teoadal/ea9c8926e6a942d46b96fe9a1faa8e22 to your computer and use it in GitHub Desktop.
Save teoadal/ea9c8926e6a942d46b96fe9a1faa8e22 to your computer and use it in GitHub Desktop.
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