public MainWindow() { InitializeComponent(); Animals = new ObservableCollection <Animal>(); Frog frog = new PolymorphismIntro.Frog(1, "Dart", true, 20); Dog dog = new PolymorphismIntro.Dog("Labradoodle", 35, "Pax", 51); Duck duck = new PolymorphismIntro.Duck(12, "Kevin", 7); Frog frog2 = new PolymorphismIntro.Frog(5, "Crazzy", false, 2); Dog dog2 = new PolymorphismIntro.Dog("Labradoodle", 7, "Sophie", 5); Duck duck2 = new PolymorphismIntro.Duck(39, "Obamuck", 500); Animals.Add(frog); Animals.Add(dog); Animals.Add(duck); Animals.Add(frog2); Animals.Add(dog2); Animals.Add(duck2); lvAnimals.ItemsSource = Animals; }
public MainWindow() { InitializeComponent(); Animals = new List <Animal>(); Frog frog = new PolymorphismIntro.Frog(4, "Kermit", false, 25); Dog dog = new PolymorphismIntro.Dog("Muppet", 20, "Rolf", 70); Duck duck = new Duck(9, "Donald", 35); Dog Clifford = new PolymorphismIntro.Dog("terrier", 200, "Clifford", 1000); Duck Daffy = new Duck(5, "Daffy", 60); Frog Jerimiah = new Frog(3, "Jerimiah", true, 15); Animals.Add(frog); Animals.Add(dog); Animals.Add(duck); Animals.Add(Clifford); Animals.Add(Daffy); Animals.Add(Jerimiah); lvAnimals.ItemsSource = Animals; foreach (Animal a in Animals) { a.SayName(); } }