Tim Van Wassenhove

Passionate geek, interested in Technology. Proud father of two

03 Sep 2006

List the month names

As i wrote in Generate a menu with month names it’s silly to hardcode month names. Here’s a C# sample using localization/globalization

using System;
using System.Globalization;
using System.Threading;

namespace ConsoleApplication1 
{
	class Program 
	{
		static void ListMonths() 
		{
			for ( int i = 1; i < 13; ++i ) 
			{ 
				DateTime dateTime = new DateTime( DateTime.Now.Year, i, 1 ); 
				Console.WriteLine( dateTime.ToString( "MMMM" ) ); 
			} 
			Console.WriteLine(); 
		} 
		
		static void Main( string[] args ) 
		{ 
			Thread.CurrentThread.CurrentCulture = new CultureInfo( "en-US", false );
			ListMonths(); 
			Thread.CurrentThread.CurrentCulture = new CultureInfo( "nl-BE", false ); 
			ListMonths(); 
			Console.Write( "{0}Press any key to continue...", Environment.NewLine ); 
			Console.ReadKey(); 
		} 
	} 
}