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
*/
Loading
Posted Oct 3, 2012, 2:15 PM
VulpesPosted Oct 3, 2012, 1:41 PM
new DateTime(1, monthNumber, 1)
The ToString("MMMM") method is then applied to this DateTime to give the full name of the month. "MMMM" is one of .NET's custom date and time formats. See this link for others:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx