Askor

Hw27

Nov 18th, 2020 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Test
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Dictionary<string, string> forms = new Dictionary<string, string>();
  11.             int userInput;
  12.             bool isUserInProgramm = true;
  13.  
  14.             while (isUserInProgramm) {
  15.                 Console.WriteLine("1 - Добавить досье | 2 - Посмотреть все досье | 3 - Удалить досье | 4 - Выйти из программы");
  16.                 userInput = Convert.ToInt32(Console.ReadLine());
  17.  
  18.                 switch (userInput)
  19.                 {
  20.                     case 1:
  21.                         AddForm(forms);
  22.                         break;
  23.                     case 2:
  24.                         ShowForms(forms);
  25.                         break;
  26.                     case 3:
  27.                         DeleteForm(forms);
  28.                         break;
  29.                     case 4:
  30.                         isUserInProgramm = false;
  31.                         break;
  32.                 }
  33.  
  34.                 Console.WriteLine("Нажмите любую клавишу для продолжения...");
  35.                 Console.ReadKey();
  36.                 Console.Clear();
  37.             }
  38.         }
  39.  
  40.         public static void AddForm(Dictionary<string, string> dict)
  41.         {
  42.             Console.WriteLine("Введите полное имя: ");
  43.             string fullName = Console.ReadLine();
  44.             Console.WriteLine("Введите Должность: ");
  45.             string post = Console.ReadLine();
  46.             dict.Add(fullName, post);
  47.         }
  48.  
  49.         public static void DeleteForm(Dictionary<string, string> dict)
  50.         {
  51.             Console.WriteLine("Введите имя чьё досье вы хотите удалить: ");
  52.             string fullName = Console.ReadLine();
  53.  
  54.             if (dict.Remove(fullName))
  55.             {              
  56.                 Console.WriteLine("Досье удалено");
  57.             }
  58.             else
  59.             {
  60.                 Console.WriteLine("Досье не найдено");
  61.             }
  62.         }
  63.  
  64.         public static void ShowForms(Dictionary<string, string> dict)
  65.         {
  66.             int i = 0;
  67.  
  68.             Console.WriteLine("Список досье:");
  69.  
  70.             foreach (var name in dict)
  71.             {
  72.                 i++;
  73.                 Console.WriteLine($"{i}.{name.Key} - {name.Value}");
  74.             }
  75.         }
  76.     }
  77. }
  78.  
Add Comment
Please, Sign In to add comment