Turn an integer into a month name
In this program please explain the reason to have 1, monthNumber and four M. Problem is highlighted.
using System;
class Test
{
static void Main()
{
string s = GetMonth(1);
Console.WriteLine(s);
s = GetMonth(12);
Console.WriteLine(s);
Console.ReadKey();
}
static string GetMonth(int monthNumber)
{
if (monthNumber < 1 || monthNumber > 12)
throw new ArgumentOutOfRangeException();
return new DateTime(1, monthNumber, 1).ToString("MMMM");
}
}
/*
January
December
*/