Beispiel #1
0
        static void Main(string[] args)
        {
            // USING CONSISTENT iterator() METHODS
            Console.WriteLine("=== Our Cars ===");
            CarRange carRange2 = new CarRange();

            PrintIterator(carRange2.GetEnumerator());

            Console.WriteLine("=== Our Vans ===");
            VanRange vanRange2 = new VanRange();

            PrintIterator(vanRange2.GetEnumerator());


            // USING FOR-EACH
            Console.WriteLine("=== Our Cars ===");
            CarRange carRange3 = new CarRange();

            foreach (IVehicle currentVehicle in carRange3.Range)
            {
                Console.WriteLine(currentVehicle);
            }

            Console.WriteLine("=== Our Vans ===");
            VanRange vanRange3 = new VanRange();

            foreach (IVehicle currentVehicle in vanRange3.Range)
            {
                Console.WriteLine(currentVehicle);
            }

            Console.Read();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello from Iterator!");

            Console.WriteLine("=== Our Cars ===");
            CarRange carRange = new CarRange();

            PrintIterator(carRange.GetEnumerator());

            Console.WriteLine("=== Our Vans ===");
            VanRange vanRange = new VanRange();

            PrintIterator(vanRange.GetEnumerator());
        }