stefan1919

Phonebook

Sep 22nd, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication7
  8. {
  9.     class Program
  10.     {
  11.        
  12.         static void Main(string[] args)
  13.         {
  14.             Dictionary<string, string> phonebook = new Dictionary<string, string>();
  15.             string input = Console.ReadLine();
  16.             string[] inputData = input.Split('-');
  17.             while (input != "search")
  18.             {
  19.                 phonebook.Add(inputData[0], inputData[1]);
  20.                 input = Console.ReadLine();
  21.                 inputData = input.Split('-');
  22.             }
  23.             Console.Clear();
  24.             string name = Console.ReadLine();
  25.             int counter = 0;
  26.             while (counter == 0)
  27.             {
  28.                 if (phonebook.ContainsKey(name) == false)
  29.                 {
  30.                     Console.WriteLine("Contact {0} does not exist.", name);
  31.                 }
  32.                 else
  33.                 {
  34.                     Console.WriteLine("{0} --> {1}", name, phonebook[name]);
  35.                 }
  36.                 name = Console.ReadLine();
  37.             }
  38.             //foreach (var name in phonebook.Keys)
  39.             //{
  40.             //    Console.WriteLine("{0} --> {1}", name, phonebook[name]);
  41.             //}
  42.         }
  43.       }
  44.    }
Advertisement
Add Comment
Please, Sign In to add comment