static void Main(string[] args) { // Build a collection Collection collection = new Collection(); collection[0] = new Employee("Tran Quang A"); collection[1] = new Employee("Le Nhat B"); collection[2] = new Employee("Le Van C"); collection[3] = new Employee("Tran Van D"); collection[4] = new Employee("Tao Nhu C"); // Create iterator Iterator iterator = collection.CreateIterator(); Console.WriteLine("Iterating over collection:"); // Get current Employee var itemCurrent = iterator.Current(); while (iterator.HasNext) { var item = iterator.Next(); Console.WriteLine(item.Name); } Console.ReadKey(); }
static void Main(string[] args) { Collection collection = new Collection(); collection[0] = new Item("Item 0"); collection[1] = new Item("Item 1"); collection[2] = new Item("Item 2"); collection[3] = new Item("Item 3"); collection[4] = new Item("Item 4"); collection[5] = new Item("Item 5"); collection[6] = new Item("Item 6"); collection[7] = new Item("Item 7"); collection[8] = new Item("Item 8"); Iterator iterator = collection.CreateIterator(); iterator.Step = 2; Console.WriteLine("Iterating over collection"); for (Item item = iterator.First(); !iterator.IsDone; item = iterator.Next()) { Console.WriteLine(item.Name); } Console.ReadKey(); }
static void Main(string[] args) { // Build a collection // Collection collection = new Collection(); Collection owce = new Collection(); owce[0] = new Item("Owca czerwona"); owce[1] = new Item("Owca pomaranczowa"); owce[2] = new Item("Owca zolta"); owce[3] = new Item("Owca zielona"); owce[4] = new Item("Owca niebieska"); owce[5] = new Item("Owca granatowa"); owce[6] = new Item("Owca fioletowa"); // Create iterator //Iterator iterator = collection.CreateIterator(); Iterator liczowce = owce.CreateIterator(); // Skip every other item liczowce.Step = 1; Console.WriteLine("Iterating over sheeps:"); for (Item item = liczowce.First(); !liczowce.IsDone; item = liczowce.Next()) { Console.WriteLine(item.Name); } Console.WriteLine("--------------------------back------------------------------------------------------"); for (Item item = liczowce.Last(); !liczowce.IsDone2; item = liczowce.Back()) { Console.WriteLine(item.Name); } // Wait for user Console.ReadKey(); }
static void Main(string[] args) { // Build a collection Collection collection = new Collection(); collection[0] = new Item("Item 0"); collection[1] = new Item("Item 1"); collection[2] = new Item("Item 2"); collection[3] = new Item("Item 3"); collection[4] = new Item("Item 4"); collection[5] = new Item("Item 5"); collection[6] = new Item("Item 6"); collection[7] = new Item("Item 7"); collection[8] = new Item("Item 8"); // Create iterator Iterator iterator = collection.CreateIterator(); // Skip every other item iterator.Step = 2; Console.WriteLine("Iterating over collection:"); for (Item item = iterator.First(); !iterator.IsDone; item = iterator.Next()) { Console.WriteLine(item.Name); } // Wait for user Console.ReadKey(); }
private static void Main() { var collection = new Collection(new List <object> { 2, 3, 4, 5, 6 }); var iterator = collection.CreateIterator(); Console.WriteLine("Iterating over collection:"); for (var item = iterator.First(); !iterator.IsDone(); item = iterator.Next()) { Console.WriteLine(item); } }
static void Main(string[] args) { Collection people = new Collection(); people[0] = new Person("Mary"); people[1] = new Person("Jane"); people[2] = new Person("John"); people[3] = new Person("Doe"); people[4] = new Person("Peter"); // Iterator IIterator <Person> iterator = people.CreateIterator(); // Iterate for (Person person = iterator.First(); !iterator.IsDone; person = iterator.Next()) { System.Console.WriteLine($"{person.Name}"); } System.Console.WriteLine(); RunRealWorlExample(); }