public static void Behavioral_IteratorDemo2() { var products = new ProductCollection(); products.Add(new Product(1, "a")); products.Add(new Product(2, "b")); products.Add(new Product(3, "c")); products.Add(new Product(4, "d")); var iterator = products.CreateIterator(); while (iterator.HasNext()) { Console.WriteLine(iterator.Current()); iterator.Next(); } }
static void Main(string[] args) { var browseHistory = new BrowseHistory <string>(); browseHistory.Push("a"); browseHistory.Push("b"); browseHistory.Push("c"); var browseHistoryIterator = browseHistory.CreateIterator(); while (browseHistoryIterator.HasNext()) { Console.WriteLine(browseHistoryIterator.Current()); browseHistoryIterator.Next(); } Console.WriteLine("--- Exercise ---"); var productCollection = new ProductCollection(); productCollection.Add(new Product(1, "Product 1")); productCollection.Add(new Product(2, "Product 2")); productCollection.Add(new Product(3, "Product 3")); var productIterator = productCollection.CreateIterator(); while (productIterator.HasNext()) { Console.WriteLine(productIterator.Current()); productIterator.Next(); } Console.ReadLine(); }