Example #1
0
        static void Main(string[] args)
        {
            Dog dog = new Dog
            {
                Name = "沙皮狗"
            };

            dog.Shout();
            dog.PrintName();
            dog.Shouts();
            Console.ReadKey();
        }
Example #2
0
        /// <summary>
        /// Demonstrates aspects of inheritance and interfaces
        /// </summary>
        public static void Main()
        {
            // Dog stored in Dog variable
            Dog dog = new Dog("Spot", "mutt");

            Console.WriteLine("Dog stored as Dog says " + dog.Speak() + " and shouts " + dog.Shout());
            Console.ReadLine();

            // Dog stored in Animal variable
            Animal animal1 = new Dog("Spot", "mutt");

            Console.WriteLine("Dog stored as Animal says " + animal1.Speak() + " and shouts " + animal1.Shout());
            Console.ReadLine();

            // Spider stored in Spider variable
            Spider spider = new Spider("Charlotte", false);

            Console.WriteLine("Spider stored as Spider says " + spider.Speak() + " and shouts " + spider.Shout());
            Console.ReadLine();

            // Spider stored in Animal variable
            Animal animal2 = new Spider("Charlotte", false);

            Console.WriteLine("Spider stored as Animal says " + animal2.Speak() + " and shouts " + animal2.Shout());
            Console.ReadLine();

            // Phone stored as Phone
            Phone phone = new Phone();

            Console.WriteLine("Phone stored as Phone says " + phone.Speak());
            Console.ReadLine();

            // All of the above, stored in an array of Speakers
            Console.WriteLine("All speak simultaneously, in the same order, after being stored as Speakers:");
            Console.WriteLine(SpeakSimultaneously(new Speaker[] { dog, animal1, spider, animal2, phone }));
            Console.ReadLine();
        }