Esempio n. 1
0
        static void Main()
        {
            // Build a collection
            ConcreteCollection collection = new ConcreteCollection();

            collection.AddProfessor(new Professor("Dr.J", 310));
            collection.AddProfessor(new Professor("Prof. Sue", 301));
            collection.AddProfessor(new Professor("Dr. Renne", 611));
            collection.AddProfessor(new Professor("Dr. Kevin", 630));
            collection.AddProfessor(new Professor("Prof. Brian", 465));
            collection.AddProfessor(new Professor("Prof. David", 448));

            // Create iterator
            Iterator iterator = collection.CreateIterator();

            //looping iterator
            Console.WriteLine("Iterating over collection:");

            for (Professor prof = iterator.First(); !iterator.IsCompleted; prof = iterator.Next())
            {
                Console.WriteLine($"CourseID : {prof .CourseID} & CourseName : {prof .CourseName}");
            }
            Console.Read();
        }
Esempio n. 2
0
 // Constructor
 public Iterator(ConcreteCollection collection)
 {
     this.collection = collection;
 }