Вы можете просто привести значение к перечислению.Не забудьте установить начальное значение для января или учесть, что по умолчанию enum начинается с 0;
Консольное приложение будет следующим:
class Program
{
public enum Month
{
January, February, March,
April, May, June, July, August,
Septemper, October, November, December
};
static void Main(string[] args)
{
Console.WriteLine("Enter the number of the month");
int monthValue = 0;
int.TryParse(Console.ReadLine(), out monthValue);
Console.WriteLine((Month)monthValue - 1);
Console.ReadKey();
}
}
, если вам не нужновременная переменная, вы также можете преобразовать ее в enum.Но не забудьте установить значение по умолчанию enum
public enum Month
{
January = 1, February, March,
April, May, June, July, August,
Septemper, October, November, December
};
static void Main(string[] args)
{
Console.WriteLine("Enter the number of the month");
var input = Enum.Parse(typeof(Month), Console.ReadLine());
Console.WriteLine(input);
Console.ReadKey();
}