Last active
August 29, 2015 14:27
-
-
Save LordJZ/8749c3798aad4e89e595 to your computer and use it in GitHub Desktop.
Infinite Enumerable
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
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