private void btnAnimal_Click(object sender, RoutedEventArgs e) { txtNourriture.Text = ""; if (!string.IsNullOrEmpty(txtAnimal.Text)) { Animal animal = new Animal(txtAnimal.Text); // Création d'un animal avec le nom voulu pour la recherche Nourriture nourriture = this.zoo[animal]; // Recherche de la nourriture correspondant à l'animal txtNourriture.Text = nourriture == null ? "Pas trouvé" : nourriture.getNom(); } }
public Nourriture this[Animal animal] { get { int i = this.animaux.IndexOf(animal); if (i > -1) { return nourritures[i]; } else { return null; } } }
public void addAnimalAuZoo(Animal animal, Nourriture nourriture) { this.animaux.Add(animal); this.nourritures.Add(nourriture); }
public bool Equals(Animal other) { return this.nom == other.nom; }