Advertisement
YORDAN2347

DictionaryHome

Apr 20th, 2021
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _20._04._21
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var groups = new Dictionary<string, string>();
  12.  
  13.             groups.Add("Group1", "Song1");
  14.             groups.Add("Group2", "Song2");
  15.             groups.Add("Group3", "Song3");
  16.             groups.Add("Group4", "Song4");
  17.             groups.Add("Group5", "Song5");
  18.  
  19.             while (true)
  20.             {
  21.                 Console.WriteLine($"Chose 1 to search by group or 2 by song");
  22.                 int num = int.Parse(Console.ReadLine());
  23.                 var input = Console.ReadLine();
  24.  
  25.                 if (num == 1)
  26.                 {
  27.                     if (groups.ContainsKey(input))
  28.                     {
  29.                         Console.WriteLine($"Song is: {groups[input]}");
  30.                     }
  31.                     else
  32.                         Console.WriteLine($"Group did not found!");
  33.                 }
  34.                 else
  35.                 {
  36.                     if (groups.ContainsValue(input))
  37.                     {
  38.                         Console.WriteLine($"Group is: {groups.First(x => x.Value == input).Key}");
  39.                     }
  40.                     else
  41.                         Console.WriteLine($"Song did not found!");
  42.                 }
  43.             }
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement