Skip to content

Instantly share code, notes, and snippets.

@RiskyWilhelm
Created June 30, 2024 13:20
Show Gist options
  • Save RiskyWilhelm/74cfb2837616b1ae7acc4c7bf655831c to your computer and use it in GitHub Desktop.
Save RiskyWilhelm/74cfb2837616b1ae7acc4c7bf655831c to your computer and use it in GitHub Desktop.
Avoid IEnumerable.GetEnumerator() garbage and iterate through an enumerator directly (C# >= 9)
using System.Collections;
public static class IEnumeratorExtensions
{
/// <summary> Allows you to iterate through an IEnumerator </summary>
public static T GetEnumerator<T>(this T enumerator)t
where T : IEnumerator
{
return enumerator;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment