Created
June 30, 2024 13:20
-
-
Save RiskyWilhelm/74cfb2837616b1ae7acc4c7bf655831c to your computer and use it in GitHub Desktop.
Avoid IEnumerable.GetEnumerator() garbage and iterate through an enumerator directly (C# >= 9)
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
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