Vapio

task23

Apr 19th, 2021 (edited)
440
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Program
  5. {
  6.     public static void Main()
  7.     {
  8.         Dictionary<string, string> dictionary = new Dictionary<string, string>()
  9.         {
  10.             { "ABOBA", "Valery ABOBA is a new candidate on a president of Ruissia in 2021."},
  11.             { "Car ", "A car (or automobile) is a wheeled motor vehicle used for transportation."}
  12.         };
  13.  
  14.         bool isRun = true;
  15.         string name;
  16.  
  17.         while (isRun)
  18.         {
  19.             name = InputName();
  20.  
  21.             if (name.Equals("Exit"))
  22.                 isRun = false;
  23.             else
  24.                 Console.WriteLine(GetValue(name, dictionary));
  25.         }
  26.     }
  27.  
  28.     public static string InputName()
  29.     {
  30.         string name;
  31.  
  32.         Console.WriteLine("Input a name : ");
  33.         name = Console.ReadLine();
  34.  
  35.         return name;
  36.     }
  37.  
  38.     public static string GetValue(string name, Dictionary<string, string> dictionary)
  39.     {
  40.         string value;
  41.         bool isNameValid = dictionary.TryGetValue(name, out value);
  42.  
  43.         if (isNameValid == false)
  44.             return value = "We haven't this name in dictionary";
  45.        
  46.         return value;
  47.     }
  48. }
RAW Paste Data