private void SayName_Button_Click(object sender, RoutedEventArgs e) { // 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 dogs.Add(dog1); dogs.Add(dog2); // Loop through the list and call a method on the objects foreach (Dog d in dogs) { d.SayName(); } // Ducks and Frogs Duck duck1 = new Duck(9, "Donald"); duck1.SayName(); Frog frog1 = new Frog(4, "Kermit", false); frog1.SayName(); }
public MainWindow() { InitializeComponent(); Animals = new ObservableCollection <Animal>(); Dog dog1 = new Dog("Muppet", 20, "Rolf"); Dog dog2 = new Dog("Golden Retriever", 30, "Air Bud"); Duck duck1 = new Duck(9, "Donald"); Frog frog1 = new Frog(4, "Kermit", false); duck1.SayName(); frog1.SayName(); Animals.Add(dog1); Animals.Add(dog2); Animals.Add(duck1); Animals.Add(frog1); LvAnimals.ItemsSource = Animals; }