Facebook
From gowno, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 161
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static List<string> persons = new List<string>();
  7.  
  8.     static void Main(string[] args)
  9.     {
  10.         bool exit = false;
  11.         while (!exit)
  12.         {
  13.             Console.WriteLine("Menu:");
  14.             Console.WriteLine("1. Dodawanie nowej osoby");
  15.             Console.WriteLine("2. Usuwanie osoby");
  16.             Console.WriteLine("3. Wyświetlanie wszystkich osób");
  17.             Console.WriteLine("4. Wyświetlanie pojedynczej osoby");
  18.             Console.WriteLine("5. Wyjście");
  19.             Console.WriteLine("Wybierz opcję:");
  20.  
  21.             string choice = Console.ReadLine();
  22.  
  23.             switch (choice)
  24.             {
  25.                 case "1":
  26.                     Console.WriteLine("Podaj imię osoby do dodania:");
  27.                     string name = Console.ReadLine();
  28.                     persons.Add(name);
  29.                     Console.WriteLine("Osoba dodana pomyślnie.");
  30.                     break;
  31.                 case "2":
  32.                     Console.WriteLine("Podaj indeks osoby do usunięcia:");
  33.                     if (int.TryParse(Console.ReadLine(), out int index) && index >= 0 && index < persons.Count)
  34.                     {
  35.                         persons.RemoveAt(index);
  36.                         Console.WriteLine("Osoba usunięta pomyślnie.");
  37.                     }
  38.                     else
  39.                     {
  40.                         Console.WriteLine("Niepoprawny indeks.");
  41.                     }
  42.                     break;
  43.                 case "3":
  44.                     Console.WriteLine("Lista osób:");
  45.                     foreach (string person in persons)
  46.                     {
  47.                         Console.WriteLine(person);
  48.                     }
  49.                     break;
  50.                 case "4":
  51.                     Console.WriteLine("Podaj indeks osoby do wyświetlenia:");
  52.                     if (int.TryParse(Console.ReadLine(), out int displayIndex) && displayIndex >= 0 && displayIndex < persons.Count)
  53.                     {
  54.                         Console.WriteLine($"Osoba na pozycji {displayIndex}: {persons[displayIndex]}");
  55.                     }
  56.                     else
  57.                     {
  58.                         Console.WriteLine("Niepoprawny indeks.");
  59.                     }
  60.                     break;
  61.                 case "5":
  62.                     exit = true;
  63.                     Console.WriteLine("Wyjście...");
  64.                     break;
  65.                 default:
  66.                     Console.WriteLine("Niepoprawna opcja. Wybierz ponownie.");
  67.                     break;
  68.             }
  69.  
  70.             Console.WriteLine("Naciśnij dowolny klawisz, aby kontynuować...");
  71.             Console.ReadKey();
  72.             Console.Clear(); // Opcjonalnie, aby czytelniej wyglądało menu po kolejnych wyborach.
  73.         }
  74.     }
  75. }
  76.