Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- Dictionary<string, string> persons = new Dictionary<string, string>();
- string choose;
- bool isRun = true;
- while (isRun)
- {
- Console.WriteLine("\nInput number of action : ");
- Console.WriteLine("1. Add case.\n" +
- "2. Output all cases.\n" +
- "3. Remove case.\n" +
- "4. Exit.");
- choose = Console.ReadLine();
- switch (choose)
- {
- case "1":
- AddCase(persons);
- break;
- case "2":
- OutputCases(persons);
- break;
- case "3":
- RemoveCase(persons);
- break;
- case "4":
- isRun = false;
- break;
- default:
- Console.WriteLine("You write wrong number of command.");
- break;
- }
- }
- }
- public static void AddCase(Dictionary<string, string> persons)
- {
- string name;
- string position;
- Console.WriteLine("Input name of person : ");
- name = Console.ReadLine();
- Console.WriteLine("Input position of person : ");
- position = Console.ReadLine();
- persons.Add(name, position);
- }
- public static void OutputCases(Dictionary<string, string> persons)
- {
- int i = 1;
- foreach (KeyValuePair<string, string> person in persons)
- {
- Console.Write($"{i}. {person.Key} - {person.Value} ");
- ++i;
- }
- Console.WriteLine();
- }
- public static void RemoveCase(Dictionary<string, string> persons)
- {
- if (persons.Count != 0)
- {
- string personName;
- bool isInput = true;
- do
- {
- Console.WriteLine($"Amount of cases : {persons.Count}");
- Console.WriteLine("Please type a name of person : ");
- personName = Console.ReadLine();
- if (persons.ContainsKey(personName))
- isInput = false;
- } while (isInput);
- persons.Remove(personName);
- }
- }
- }
Add Comment
Please, Sign In to add comment