Maha

Maha

  • NA
  • 0
  • 310k

Turn an integer into a month name

Oct 3 2012 11:33 AM
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
*/

Answers (2)