コード例 #1
0
ファイル: Program.cs プロジェクト: Sntai20/CSC180
        static void Main()
        {
            // Create new local object theZoo, then add mammals and birds.
            Zoo theZoo = new Zoo();

            theZoo.AddMammal("Whale");
            theZoo.AddMammal("Rhinoceros");
            theZoo.AddBird("Penguin");
            theZoo.AddBird("Warbler");

            // Iterate through each name in the theZoo.
            foreach (string name in theZoo)
            {
                Console.Write(name + " ");
            }
            Console.WriteLine();

            // Iterate through bird names in theZoo.
            foreach (string name in theZoo.Birds)
            {
                Console.Write(name + " ");
            }
            Console.WriteLine();

            // Iterate through mammal names in theZoo.
            foreach (string name in theZoo.Mammals)
            {
                Console.Write(name + " ");
            }
            Console.WriteLine();
            Console.ReadKey();
        }
コード例 #2
0
    //<Snippet24>
    static void Main()
    {
        Zoo theZoo = new Zoo();

        theZoo.AddMammal("Whale");
        theZoo.AddMammal("Rhinoceros");
        theZoo.AddBird("Penguin");
        theZoo.AddBird("Warbler");

        foreach (string name in theZoo)
        {
            Console.Write(name + " ");
        }
        Console.WriteLine();
        // Output: Whale Rhinoceros Penguin Warbler

        foreach (string name in theZoo.Birds)
        {
            Console.Write(name + " ");
        }
        Console.WriteLine();
        // Output: Penguin Warbler

        foreach (string name in theZoo.Mammals)
        {
            Console.Write(name + " ");
        }
        Console.WriteLine();
        // Output: Whale Rhinoceros

        Console.ReadKey();
    }
コード例 #3
0
        private void IteratorsUsage()
        {
            Zoo zoo = new Zoo();

            zoo.AddMammal("Whale");
            zoo.AddMammal("Rhinoceros");
            zoo.AddBird("Penguin");
            zoo.AddBird("Warbler");

            PrintAnimalName(zoo);
            PrintAnimalName(zoo.Birds);
            PrintAnimalName(zoo.Mammals);
        }