Advertisement
YORDAN2347

MonthsDictionary

Mar 23rd, 2021
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace DictionaryMonths
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Dictionary<int, string> months = new Dictionary<int, string>();
  11.             months.Add(1, "January");
  12.             months.Add(2, "February");
  13.             months.Add(3, "March");
  14.             months.Add(4, "April");
  15.             months.Add(5, "May");
  16.             months.Add(6, "June");
  17.             months.Add(7, "July");
  18.             months.Add(8, "August");
  19.             months.Add(9, "September");
  20.             months.Add(10, "October");
  21.             months.Add(11, "November");
  22.             months.Add(12, "December");
  23.  
  24.             Console.WriteLine("Enter 1 to get Number of Month, Enter 2 to get name");
  25.             int option = int.Parse(Console.ReadLine());
  26.             if (option == 1)
  27.             {
  28.                 Console.WriteLine("Enter month name");
  29.                 string name = Console.ReadLine();
  30.                 foreach (var month in months)
  31.                 {
  32.                     if (month.Value == name)
  33.                     {
  34.                         Console.WriteLine(month.Key);
  35.                         break;
  36.                     }
  37.                 }
  38.             }
  39.             else
  40.             {
  41.                 Console.WriteLine("Enter month number");
  42.                 int num = int.Parse(Console.ReadLine());
  43.                 Console.WriteLine(months[num]);
  44.             }
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement