static void Main(string[] args) { do { Console.WriteLine("Select menu program: "); Console.WriteLine("1. Create a Crocodile: "); Console.WriteLine("2. Create a Cat: "); Console.WriteLine("3. Create a Fish: "); Console.WriteLine("4. View Terrestrial Animals: "); Console.WriteLine("5. View Marine Animals: "); Console.WriteLine("6. View All Animals: "); Console.WriteLine("7. Delete Animal: "); Console.WriteLine("8. Exit: "); select = Convert.ToInt32(Console.ReadLine()); switch (select) { case 1: Crocodile crocodile = new Crocodile(); crocodile.creatCrocodile(); iAnimal.Add(crocodile); break; case 2: Cat cat = new Cat(); cat.creatCat(); iAnimal.Add(cat); break; case 3: Fish fish = new Fish(); fish.creatFish(); iAnimal.Add(fish); break; case 4: foreach (var item in iAnimal) { if (item is IMarineAnimal) { Console.WriteLine(item.ToString()); item.Move(); } } break; case 5: foreach (var item in iAnimal) { if (item is ITerrestrialAnimal) { Console.WriteLine(item.ToString()); item.Move(); } } break; case 6: foreach (var item in iAnimal) { Console.WriteLine(item.ToString()); item.Move();; } break; case 7: foreach (var item in iAnimal) { Console.WriteLine(item.ToString()); } Console.WriteLine("Nhap ID Animal muon xoa:"); int number = Convert.ToInt32(Console.ReadLine()); foreach (var item in iAnimal) { if (item.ID == number) { iAnimal.Remove(item); break; } } break; } } while(select != 8); }
static void Main(string[] args) { var list = new List <int>(); for (int i = 0; i < list.Count; i++) { Console.WriteLine($"Wartosc wynosi: {list[i]}"); } for (int i = 0; i < list.Count; i++) { var item = list[i]; Console.WriteLine($"Wartosc wynosi: {item}"); } foreach (var item in list) { Console.WriteLine($"Wartosc wynosi: {item}"); } foreach (int item in list) { Console.WriteLine($"Wartosc wynosi: {item}"); } /* * Zoo zoo = new Zoo(); * zoo.Add(new Dog()); * zoo.Add(new Bird()); * zoo.Add(new Fish()); * zoo.MoveAll(); */ Console.ReadLine(); Console.WriteLine("Type animals You want to add:"); Console.WriteLine("Type Exit to close program"); while (true) { string animal = Console.ReadLine(); if (animal == "Exit") { break; } else if (animal == "dog") { Animal an = new Dog(12, 23); ((Dog)an).Jump(); // rzutowanie - doczytać!!!! an.Move(); } else if (animal == "bird") { Bird bird = new Bird(); bird.Age = 12; bird.Size = 2; bird.Move(); } else if (animal == "fish") { Fish fish = new Fish(); fish.Move(); } } }