Advertisement
SPavelA

Task1Dictionary

Sep 23rd, 2024
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | Gaming | 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 CollectionsTask1Dictionary
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             const string CommandExit = "q";
  14.  
  15.             Dictionary <string, string> worlds = new Dictionary<string, string>();
  16.             bool isWorking = true;
  17.             string userInput;
  18.            
  19.             worlds.Add("привет", "говорят люди, когда встречают друг друга");
  20.             worlds.Add("муж", "объелся груш");
  21.             worlds.Add("жена", "сама сатана");
  22.             worlds.Add("дом", "современная пещера");
  23.             Console.WriteLine("Добро пожаловать в наш толковый словарь!");
  24.  
  25.             while (isWorking)
  26.             {
  27.                 Console.WriteLine($"Для выхода введите \"{CommandExit}\".");
  28.                 Console.WriteLine("Какое слово вы хотите узнать?");
  29.                 userInput = Console.ReadLine();
  30.  
  31.                 if (userInput == CommandExit)
  32.                 {
  33.                     isWorking = false;
  34.                 }
  35.                 else if (worlds.ContainsKey(userInput))
  36.                 {
  37.                     Console.WriteLine($"{userInput} - {worlds[userInput]}");
  38.                 }
  39.                 else
  40.                 {
  41.                     Console.WriteLine("Такого слова нет в нашем словаре, попробуйте другое.");
  42.                 }
  43.             }
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement