Skip to content

Instantly share code, notes, and snippets.

@LordJZ
Last active August 29, 2015 14:27
Show Gist options
  • Save LordJZ/8749c3798aad4e89e595 to your computer and use it in GitHub Desktop.
Save LordJZ/8749c3798aad4e89e595 to your computer and use it in GitHub Desktop.
Infinite Enumerable
class InfiniteEnumerable : IEnumerable<long>
{
public struct Enumerator : IEnumerator<long>
{
public void Dispose()
{
}
public bool MoveNext()
{
++Current;
return true;
}
public void Reset()
{
this.Current = 0;
}
public long Current { get; private set; }
object IEnumerator.Current => Current;
}
private InfiniteEnumerable()
{
}
public static readonly InfiniteEnumerable Instance = new InfiniteEnumerable();
public Enumerator GetEnumerator() => new Enumerator();
IEnumerator IEnumerable.GetEnumerator() => new Enumerator();
IEnumerator<long> IEnumerable<long>.GetEnumerator() => new Enumerator();
}
foreach (long iteration in InfiniteEnumerable.Instance)
{
// whoa dude
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment