예제 #1
0
        private void SayName_Button_Click(object sender, RoutedEventArgs e)
        {
            List <animal> animals = new List <animal>();
            // Define a new List of dogs
            // List<Dog> dogs = new List<Dog>();

            // Instantiate some dog objects
            Dog dog1 = new Dog("Muppet", 20, "Rolf");
            Dog dog2 = new Dog("Golden Retriever", 30, "Air Bud");

            // Add the dogs to the list
            animals.Add(dog1);
            animals.Add(dog2);

            // Loop through the list and call a method on the objects
            //foreach (Dog d in dogs)
            // {
            //    d.SayName();
            // }
            duck duck1 = new duck(25, "Harry");
            duck duck2 = new duck(45, "Henrietta");

            //List<duck> ducks = new List<duck>();
            animals.Add(duck1);
            animals.Add(duck2);

            foreach (animal animal in animals)
            {
                animal.SayName();
                MessageBox.Show("The height is " + animal.Height);
            }
            Frog        frog1 = new Frog("No", "Bo");
            Frog        frog2 = new Frog("Yes", "Spiky");
            List <Frog> frogs = new List <Frog>();

            frogs.Add(frog1);
            frogs.Add(frog2);
            foreach (Frog frog in frogs)
            {
                frog.SayName();
            }
        }
예제 #2
0
        private void Quack_Button_Click(object sender, RoutedEventArgs e)
        {
            duck duck = new duck(0, "mom");

            duck.Quack();
        }
예제 #3
0
        private void quackbutton_Click(object sender, RoutedEventArgs e)
        {
            duck duck = new duck();

            duck.quack();
        }