using System;
using System.Collections.Generic;
class Test
{
   static IEnumerable<int> FromTo(int from, int to) {
      while (from <= to)
         yield return from++;
   }
   static void Main() {
      IEnumerable<int> e = FromTo(1, 10);
      foreach (int x in e) {
         foreach (int y in e) {
            Console.Write("{0,3} ", x * y);
         }
         Console.WriteLine();
      }  
   }
}

Example 5: C# iterators.

Back to Article