Iteratoren mit yield

class Range : IEnumerable<int> {
    private readonly int lo;
    private readonly int hi;
    public Range(int lo, int hi) {
        this.lo = lo; this.hi = hi;
    }
    public IEnumerator<int> GetEnumerator() {
        for (int x = lo; x < hi ; x++) {
           yield return x;
        }
        yield break;
    }
}



Johannes Waldmann 2011-07-07