Getting the name of the month.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under Visual Studio category on | Points: 40 | Views : 223
Write below code:-
public string GetMonthName(int MonthNumber)
{
if (MonthNumber < 1 || MonthNumber > 12)
return string.Empty;

string[] Months = { "January", "February", "March", "April", "May", "June", "July", "August", "September",

"October", "November", "December" };
return Months[MonthNumber - 1];
}


Now,to test above function:-
Response.Write(GetMonthName(1));
Response.Write("<br/>");
Response.Write(GetMonthName(2));
Response.Write("<br/>");
Response.Write(GetMonthName(5));
Response.Write("<br/>");
Response.Write(GetMonthName(7));
Response.Write("<br/>");
Response.Write(GetMonthName(12));
Response.Write("<br/>");

Output:-
January
February
May
July
December

Comments or Responses

Login to post response