Create an enumeration named Month that holds values for the months of the year, starting with January equal to 1. Write a program that prompts the user for a month integer. Convert the user’s entry to a Month value, and display it.
using System;
namespace ConsoleApp1
{
class Program
{
public enum Month
{
January = 1,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
}
static void Main(string[] args)
{
string str = "";
int Number;
while (str != "Exit" && str != "E" && str != "exit" && str != "e")
{
Console.Write("Write a number from 1 to 12 (Or write the Exit): ");
str = Console.ReadLine();
if (int.TryParse(str, out Number))
if (Number >= 1 && Number <= 12)
Console.WriteLine((Month)Number);
}
}
}
}
Comments
Leave a comment