kwest87

Untitled

Dec 3rd, 2022
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. [StartCode]
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. /*
  9.  * Создать программу, которая принимает от пользователя слово и выводит его значение. Если такого слова нет, то следует вывести соответствующее сообщение.
  10.  */
  11.  
  12. namespace ConsoleApp4
  13. {
  14.     internal class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             Dictionary<int, string> shelf = new Dictionary<int, string>();
  19.             shelf.Add(1, "Пушкин");
  20.             shelf.Add(2, "Толстой");
  21.             shelf.Add(3, "Лермонтов");
  22.             shelf.Add(4, "Гоголь");
  23.             shelf.Add(5, "Донцова");
  24.             Console.Write("Укажите цифру :");
  25.             int userInput = int.Parse(Console.ReadLine());
  26.             DisplayAuthor(shelf, userInput);
  27.         }
  28.  
  29.         static void DisplayAuthor(Dictionary<int, string> shelf, int userInput)
  30.         {
  31.             if (shelf.ContainsKey(userInput))
  32.             {
  33.                 Console.WriteLine(shelf[userInput]);
  34.             }
  35.             else
  36.             {
  37.                 Console.WriteLine("Таких писателей нету.");
  38.             }
  39.         }
  40.     }
  41. }
  42. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment