static void Main(string[] args) { var agregate = new ConcreteAggregate <int>(); agregate[0] = 1; agregate[1] = 2; agregate[2] = 3; agregate[3] = 4; var iterator = new ConcreteIterator <int>(agregate); for (var item = iterator.First(); item != null; item = iterator.Next()) { Console.WriteLine(item); } Console.ReadKey(); }
static void Main(string[] args) { ConcreteAggregate <string> a = new ConcreteAggregate <string>(); a[0] = "Item A"; a[1] = "Item B"; a[2] = "Item C"; a[3] = "Item D"; ConcreteIterator <string> i = new ConcreteIterator <string>(a); Console.WriteLine("Iterating over collection:"); var item = i.First(); while (item != null) { Console.WriteLine(item); item = i.Next(); } Console.ReadKey(); }