Beispiel #1
0
        //Main -- Demonstrate five different applications of
        //   iterator blocks.
        static void Main(string[] args)
        {
            // Instantiate a MonthDays "collection" class.
            MonthDays md = new MonthDays();
            // Iterate it.
            Console.WriteLine("Stream of months:\n");
            foreach (string month in md)
            {
                Console.WriteLine(month);
            }

            // Instantiate a StringChunks "collection" class.
            StringChunks sc = new StringChunks();
            // Iterate it: prints pieces of text.
            // This iteration puts each chunk on its own line.
            Console.WriteLine("\nstream of string chunks:\n");
            foreach (string chunk in sc)
            {
                Console.WriteLine(chunk);
            }
            // And this iteration puts it all on one line.
            Console.WriteLine("\nstream of string chunks on one line:\n");
            foreach (string chunk in sc)
            {
                Console.Write(chunk);
            }
            Console.WriteLine();

            // Instantiate a YieldBreakEx "collection" class.
            YieldBreakEx yb = new YieldBreakEx();
            // Iterate it, but stop after 13.
            Console.WriteLine("\nstream of primes:\n");
            foreach (int prime in yb)
            {
                Console.WriteLine(prime);
            }

            // Instantiate an EvenNumbers "collection" class.
            EvenNumbers en = new EvenNumbers();
            // Iterate it: prints even numbers from 10 down to 4.
            Console.WriteLine("\nstream of descending evens :\n");
            foreach (int even in en.DescendingEvens(11, 3))
            {
                Console.WriteLine(even);
            }

            // Instantiate a PropertyIterator "collection" class.
            PropertyIterator prop = new PropertyIterator();
            // Iterate it: produces one double at a time.
            Console.WriteLine("\nstream of double values:\n");
            foreach (double db in prop.DoubleProp)
            {
                Console.WriteLine(db);
            }

            // Wait for the user to acknowledge.
            Console.WriteLine("Press enter to terminate...");
            Console.Read();
        }
Beispiel #2
0
        //Main -- Demonstrate five different applications of
        //   iterator blocks.
        static void Main(string[] args)
        {
            // Instantiate a MonthDays "collection" class.
            MonthDays md = new MonthDays();

            // Iterate it.
            Console.WriteLine("Stream of months:\n");
            foreach (string month in md)
            {
                Console.WriteLine(month);
            }

            // Instantiate a StringChunks "collection" class.
            StringChunks sc = new StringChunks();

            // Iterate it: prints pieces of text.
            // This iteration puts each chunk on its own line.
            Console.WriteLine("\nstream of string chunks:\n");
            foreach (string chunk in sc)
            {
                Console.WriteLine(chunk);
            }

            // And this iteration puts it all on one line.
            Console.WriteLine("\nstream of string chunks on one line:\n");
            foreach (string chunk in sc)
            {
                Console.Write(chunk);
            }
            Console.WriteLine();

            // Instantiate a YieldBreakEx "collection" class.
            YieldBreakEx yb = new YieldBreakEx();

            // Iterate it, but stop after 13.
            Console.WriteLine("\nstream of primes:\n");
            foreach (int prime in yb)
            {
                Console.WriteLine(prime);
            }


            // Instantiate an EvenNumbers "collection" class.
            EvenNumbers en = new EvenNumbers();

            // Iterate it: prints even numbers from 10 down to 4.
            Console.WriteLine("\nstream of descending evens :\n");
            foreach (int even in en.DescendingEvens(11, 3))
            {
                Console.WriteLine(even);
            }

            // Instantiate a PropertyIterator "collection" class.
            PropertyIterator prop = new PropertyIterator();

            // Iterate it: produces one double at a time.
            Console.WriteLine("\nstream of double values:\n");
            foreach (double db in prop.DoubleProp)
            {
                Console.WriteLine(db);
            }

            // Wait for the user to acknowledge.
            Console.WriteLine("Press enter to terminate...");
            Console.Read();
        }