Wednesday, December 16, 2009

How to get all Culture information using C#

The CultureInfo class will provide us all Culture information available in .Net Framework.  You can use CultureInfo.Get­Cultures static method for getting all the culture information. To get associated specific culture, please use static method CultureInfo.Cre­ateSpecificCul­ture. 

The following example will show you how to get all culture information.

static void Main(string[] args)
{
     // Get culture names
     List<string> list = new List<string>();
     foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures))
     {
          string specName = "(none)";
          try { specName = CultureInfo.CreateSpecificCulture(ci.Name).Name;}
          catch(Exception) { }

          list.Add(string.Format("{0,-12}{1,-12}{2}", ci.Name, specName, ci.EnglishName));
     }

     list.Sort();

     Console.WriteLine("CULTURE  SPEC.CULTURE  ENGLISH NAME");
     Console.WriteLine("----------------------------------------------------");

     foreach (string str in list)
          Console.WriteLine(str);

     Console.ReadLine();
}

Post a Comment