Advertisement
dsavov_02

тел указател

Mar 23rd, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Program
  6. {
  7. public static void Main()
  8. {
  9. Dictionary<string, string> phonebook = new Dictionary<string, string>();
  10.  
  11. while (true)
  12. {
  13. Console.WriteLine("1. Изпечатай целия тел. указател");
  14. Console.WriteLine("2. Добави нов номер");
  15. Console.WriteLine("3. Изтриий номер");
  16. Console.WriteLine("4. Потърси номер");
  17. Console.WriteLine("5. Излез");
  18. string command = Console.ReadLine();
  19. if (command == "1")
  20. {
  21. foreach (var el in phonebook)
  22. {
  23. Console.WriteLine("{0} -> {1}", el.Key, el.Value);
  24. }
  25. }
  26. else if (command == "2")
  27. {
  28. Console.Write("Въведи име и номер; ");
  29. string[] input = Console.ReadLine().Split(' ');
  30. phonebook[input[0]] = input[1];
  31. }
  32. else if (command == "3")
  33. {
  34. string[] input = Console.ReadLine().Split(' ');
  35. phonebook.Remove(input[0]);
  36. }
  37. else if (command == "4")
  38. {
  39. string name = Console.ReadLine();
  40. if (phonebook.ContainsKey(name))
  41. {
  42. Console.WriteLine(phonebook[name]);
  43. }
  44. else
  45. {
  46. Console.WriteLine("Номера не съществува");
  47. }
  48. }
  49. else if (command == "5")
  50. {
  51. break;
  52. }
  53. Console.ReadLine();
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement