Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.77 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace CollectionsExtensions
  5. {
  6.     public class Program
  7.     {
  8.         public static void Main()
  9.         {
  10.             var array = new [] { 1, 3, 5, 7, 11, 13, 17, 19 };
  11.            
  12.             // ridiculous example - since this could be simplified
  13.             // by using foreach and an enumerator.
  14.             var iterator = array.GetIterator();
  15.  
  16.             while (iterator.HasCurrent)
  17.             {
  18.                 Console.WriteLine(iterator.Current);
  19.                 iterator.MoveNext();
  20.             }
  21.  
  22.  
  23.             iterator = Enumerable.Empty<int>().GetIterator();
  24.             while (iterator.HasCurrent)
  25.             {
  26.                 Console.WriteLine(iterator.Current);
  27.                 iterator.MoveNext();
  28.             }
  29.  
  30.         }
  31.     }
  32. }