using System; using System.Collections.Generic; class Program { static List persons = new List(); static void Main(string[] args) { bool exit = false; while (!exit) { Console.WriteLine("Menu:"); Console.WriteLine("1. Dodawanie nowej osoby"); Console.WriteLine("2. Usuwanie osoby"); Console.WriteLine("3. Wyświetlanie wszystkich osób"); Console.WriteLine("4. Wyświetlanie pojedynczej osoby"); Console.WriteLine("5. Wyjście"); Console.WriteLine("Wybierz opcję:"); string choice = Console.ReadLine(); switch (choice) { case "1": Console.WriteLine("Podaj imię osoby do dodania:"); string name = Console.ReadLine(); persons.Add(name); Console.WriteLine("Osoba dodana pomyślnie."); break; case "2": Console.WriteLine("Podaj indeks osoby do usunięcia:"); if (int.TryParse(Console.ReadLine(), out int index) && index >= 0 && index < persons.Count) { persons.RemoveAt(index); Console.WriteLine("Osoba usunięta pomyślnie."); } else { Console.WriteLine("Niepoprawny indeks."); } break; case "3": Console.WriteLine("Lista osób:"); foreach (string person in persons) { Console.WriteLine(person); } break; case "4": Console.WriteLine("Podaj indeks osoby do wyświetlenia:"); if (int.TryParse(Console.ReadLine(), out int displayIndex) && displayIndex >= 0 && displayIndex < persons.Count) { Console.WriteLine($"Osoba na pozycji {displayIndex}: {persons[displayIndex]}"); } else { Console.WriteLine("Niepoprawny indeks."); } break; case "5": exit = true; Console.WriteLine("Wyjście..."); break; default: Console.WriteLine("Niepoprawna opcja. Wybierz ponownie."); break; } Console.WriteLine("Naciśnij dowolny klawisz, aby kontynuować..."); Console.ReadKey(); Console.Clear(); // Opcjonalnie, aby czytelniej wyglądało menu po kolejnych wyborach. } } }