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 Program
{
enum Month
{
January = 1,
February = 2,
March = 3,
April = 4,
May = 5,
June = 6,
July = 7,
August = 8,
September = 9,
October = 10,
November = 11,
December = 12
}
class Program
{
static void Main(string[] args)
{
Console.Write("Enter month number: ");
string input = Console.ReadLine();
int month_num = Int32.Parse(input);
Month month = (Month)month_num;
Console.WriteLine(month.ToString());
}
}
}
Comments
Leave a comment