RedFlys

CSharpLight HomeWork - CardFilePro

Feb 2nd, 2021 (edited)
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace CSharpLight_HomeWork_CardFilePro
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Dictionary<string, string> cardFile = new Dictionary<string, string>();
  11.             string userInput;
  12.             bool working = true;
  13.  
  14.             while (working)
  15.             {
  16.                 WriteCommands();
  17.                 userInput = Console.ReadLine();
  18.                 Console.Clear();
  19.  
  20.                 switch (userInput)
  21.                 {
  22.                     case "1":
  23.                         AddFile(cardFile);
  24.                         Console.Clear();
  25.                         break;
  26.                     case "2":
  27.                         ShowFiles(cardFile);
  28.                         break;
  29.                     case "3":
  30.                         DeleteFile(cardFile);
  31.                         Console.Clear();
  32.                         break;                  
  33.                     case "4":
  34.                         Console.WriteLine("До свидания.");
  35.                         working = false;
  36.                         break;
  37.                     default:
  38.                         Console.WriteLine("Некорректный номер команды.");
  39.                         break;
  40.                 }
  41.             }
  42.             Console.ReadKey();
  43.         }
  44.  
  45.         static void AddFile(Dictionary<string, string> cardFile)
  46.         {
  47.             string name;
  48.             string position;
  49.             Console.Write("Введите ФИО: ");
  50.             name = Console.ReadLine();
  51.             Console.Write("Введите должность: ");
  52.             position = Console.ReadLine();
  53.            
  54.             cardFile.Add(name, position);
  55.         }
  56.  
  57.         static void ShowFiles(Dictionary<string, string> cardFile)
  58.         {
  59.             foreach (var file in cardFile)
  60.             {
  61.                 Console.WriteLine($"{file.Key} - {file.Value}");
  62.             }
  63.         }
  64.  
  65.         static void DeleteFile(Dictionary<string, string> cardFile)
  66.         {
  67.             Console.WriteLine("Введите ФИО человека, которого хотите удалить из досье.");
  68.             string userValue = Console.ReadLine();
  69.             cardFile.Remove(userValue);
  70.         }      
  71.  
  72.         static void WriteCommands()
  73.         {
  74.             Console.WriteLine("1. Добавить досье.");
  75.             Console.WriteLine("2. Вывести все досье.");
  76.             Console.WriteLine("3. Удалить досье.");
  77.             Console.WriteLine("4. Выход.");
  78.             Console.Write("Введите номер команды: ");
  79.         }        
  80.     }    
  81. }
Add Comment
Please, Sign In to add comment