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






yield return

 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program {
    public static IEnumerable<string> SimpleList() {
        yield return "1";
        yield return "2";
        yield return "3";
    }

    public static void Main(string[] args) {
        foreach (String item in SimpleList())
            Console.WriteLine(item);

    }
}

 








Related examples in the same category

1.return IEnumerable
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