kvadrat4o

Dictionaries_LINQ_Lambda_PhoneBook

Jun 14th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. /*
  2.  * Created by SharpDevelop.
  3.  * User: DVasilev
  4.  * Date: 2017/06/13
  5.  * Time: 11:29 AM
  6.  *
  7.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8.  */
  9. using System;
  10. using System.Linq;
  11. using System.Collections.Generic;
  12.  
  13.  
  14. namespace Phonebook
  15. {
  16.     class Program
  17.     {
  18.         public static void Main(string[] args)
  19.         {
  20.             //Console.WriteLine("Hello World!");
  21.             Dictionary<string, string> phoneDetails = new Dictionary<string, string>();
  22.            
  23.             List<string> commands = Console.ReadLine().Split(' ').ToList();
  24.             string token = commands[0];
  25.             if (commands[0] == "END")
  26.             {
  27.                 return;
  28.             }
  29.             else
  30.             {
  31.                 while (commands[0] != "END")
  32.                 {
  33.                     switch (commands[0])
  34.                     {
  35.                         case"A":
  36.                             string index = commands[1];
  37.                             string entry = commands[2];
  38.                             phoneDetails.Add(index,entry);
  39.                         break;
  40.                         case"S":
  41.                             string searched  = commands[1];
  42.                             string result = null;
  43.                             if (phoneDetails.TryGetValue(searched, out result))
  44.                             {
  45.                                 Console.WriteLine("{0} -> {1}", searched,result);
  46.                             }
  47.                             else
  48.                             {
  49.                                 Console.WriteLine("Contact {0} does not exist.",searched);
  50.                             }
  51.                         break;
  52.                     }
  53.                 }
  54.             }
  55.             Console.Write("Press any key to continue . . . ");
  56.             Console.ReadKey(true);
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment