return IEnumerable : IEnumerable « Class Interface « C# / C Sharp






return IEnumerable

 


using System;
using System.Collections.Generic;

class IteratorDemo {
    static IEnumerable<int> OneTwoThree() {
        Console.WriteLine("Returning 1");
        yield return 1;
        Console.WriteLine("Returning 2");
        yield return 2;
        Console.WriteLine("Returning 3");
        yield return 3;
    }
    static void Main() {
        foreach (var number in OneTwoThree()) {
            Console.WriteLine(number);
        }
    }
}

 








Related examples in the same category

1.yield return
2.Return IEnumerable by yield
3.iterates a collection forward and reverse
4.Extends IEnumerable
5.IEnumerable with a foreach loop
6.Enumerator Example (Versioned Collection)
7.Tree Enumerator