Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace DictionaryMonths
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<int, string> months = new Dictionary<int, string>();
- months.Add(1, "January");
- months.Add(2, "February");
- months.Add(3, "March");
- months.Add(4, "April");
- months.Add(5, "May");
- months.Add(6, "June");
- months.Add(7, "July");
- months.Add(8, "August");
- months.Add(9, "September");
- months.Add(10, "October");
- months.Add(11, "November");
- months.Add(12, "December");
- Console.WriteLine("Enter 1 to get Number of Month, Enter 2 to get name");
- int option = int.Parse(Console.ReadLine());
- if (option == 1)
- {
- Console.WriteLine("Enter month name");
- string name = Console.ReadLine();
- foreach (var month in months)
- {
- if (month.Value == name)
- {
- Console.WriteLine(month.Key);
- break;
- }
- }
- }
- else
- {
- Console.WriteLine("Enter month number");
- int num = int.Parse(Console.ReadLine());
- Console.WriteLine(months[num]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement