Exemple #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 animals)
            //{
            //    d.SayName();
            //}

            //List<Duck> ducks = new List<Duck> ();

            Duck duck1 = new Duck(25, "Harry");
            Duck duck2 = new Duck(45, "Henrietta");

            animals.Add(duck1);
            animals.Add(duck2);

            //foreach (Duck d in animals)
            //{
            //    d.SayName();
            //}

            //List<Frog> frogs = new List<Frog>();

            Frog frog1 = new Frog(25, "Croak", true);
            Frog frog2 = new Frog(45, "Pepe", false);

            animals.Add(frog1);
            animals.Add(frog2);

            //foreach (Frog f in animals)
            //{
            //    f.SayName();
            //}


            Cow cow1 = new Cow(25, "Lennard", "brown");
            Cow cow2 = new Cow(45, "Harold", "white");

            animals.Add(cow1);
            animals.Add(cow2);

            //foreach (Cow c in cows)
            //{
            //    c.SayName();
            //}
            foreach (Animal a in animals)
            {
                a.SayName();
                MessageBox.Show("The height is " + a.Height);
            }
        }
Exemple #2
0
        private void Moo_Button_Click(object sender, RoutedEventArgs e)
        {
            Cow cow = new Cow();

            cow.Moo();
        }