Anonim_999

Словарь

Mar 13th, 2021 (edited)
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using System.Collections.Generic;
  4. using static System.Math;
  5. using System.Text;
  6. namespace homework
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             bool isContinue = true;
  13.             Dictionary<string,string> dict = new Dictionary<string, string>();
  14.             dict.Add("Яблоко","сочный плод, который употребляется в пищу в свежем виде" );
  15.             dict.Add("Стол","предмет обихода, мебельное изделие");
  16.            
  17.             while(isContinue)
  18.             {
  19.                 WriteColoredText("команда для выхода из программы: exit\nВведите слово или команду: ");
  20.                 string userInput = Console.ReadLine();
  21.  
  22.                 if(dict.ContainsKey(userInput))
  23.                 {
  24.                     Console.WriteLine(dict[userInput]);
  25.                 }
  26.                 else if(userInput == "exit")
  27.                 {
  28.                     isContinue = false;
  29.                 }
  30.                 else
  31.                 {
  32.                     WriteColoredText("Такого значения в словаре нету\n", ConsoleColor.Red);
  33.                 }
  34.             }
  35.         }
  36.  
  37.         private static void WriteColoredText(string text, ConsoleColor color = ConsoleColor.Yellow)
  38.         {
  39.             Console.ForegroundColor = color;
  40.             Console.Write(text);
  41.             Console.ResetColor();
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment