using System; using System.Collections; using System.Collections.Generic; namespace IteratorExample { public class OneToTen : IEnumerable { public IEnumerator GetEnumerator() { for (int i = 1; i <= 10; i++) { yield return i; } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } class Program { static void Main(string[] args) { OneToTen ott = new OneToTen(); foreach (int i in ott) { Console.WriteLine(i); } Console.ReadLine(); } } }