Created
October 4, 2011 23:08
-
-
Save einarwh/1263114 to your computer and use it in GitHub Desktop.
Simple iterator for the positive integers.
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
public class Incrementer : IEnumerable<int> | |
{ | |
public IEnumerator<int> GetEnumerator() | |
{ | |
return new IncrementingEnumerator(); | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return GetEnumerator(); | |
} | |
} | |
public class IncrementingEnumerator : IEnumerator<int> | |
{ | |
private int _n; | |
public bool MoveNext() | |
{ | |
++_n; | |
return true; | |
} | |
public int Current | |
{ | |
get { return _n; } | |
} | |
object IEnumerator.Current | |
{ | |
get { return Current; } | |
} | |
public void Dispose() { } | |
public void Reset() | |
{ | |
_n = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment