static void Main(string[] args)
{
var AllMonths = Enumerable.Range(1, 12).Select(a => new
{
Name = System.Globalization.DateTimeFormatInfo.CurrentInfo.GetMonthName(a).ToUpper(),
Code = a.ToString()
});
foreach (var month in AllMonths)
{
Console.WriteLine(string.Format("Month No {0} Month Name {1} ", month.Code, month.Name));
}
}
By using Linq we can get the month names in one line code. In the above code I used AllMoths variable. Enumerable.Range gives the number between the Range that we pass in parameters. Using GetMonthName function I got the month name and getting the number (a) as month number and I am printing in separate foreach loop.