NastySwipy

Dictionaries_Lambda_Expressions_LINQ - 01. Phonebook

May 2nd, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _07b_Dictionaries_Lambda_Expressions_LINQ_Exercises
  6. {
  7.     class Dictionaries_Lambda_Expressions_LINQ_Exercises
  8.     {
  9.        static void Main(string[] args)
  10.         {
  11.             List<string> commands = Console.ReadLine().Split().ToList();
  12.             Dictionary<string, string> contacts = new Dictionary<string, string>();
  13.  
  14.             while (commands[0] != "END")
  15.             {
  16.                 if (commands[0] == "A")
  17.                 {
  18.                     if (contacts.ContainsKey(commands[1]))
  19.                     {
  20.                         contacts[commands[1]] = commands[2];
  21.                     }
  22.                     else
  23.                     {
  24.                        contacts.Add(commands[1], commands[2]);
  25.                     }
  26.                    
  27.                 }
  28.                 else if (commands[0] == "S")
  29.                 {
  30.                         if (contacts.ContainsKey(commands[1]))
  31.                         {
  32.                             Console.WriteLine($"{commands[1]} -> {contacts[commands[1]]}");
  33.                         }
  34.                         else
  35.                         {
  36.                             Console.WriteLine($"Contact {commands[1]} does not exist.");
  37.                         }
  38.                 }
  39.                 commands = Console.ReadLine().Split().ToList();
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment