Jul 1, 2012

How to get all culture names in the .NET?

2 comments
Following example shows how to get all culture names in the .NET Framework. Use static method CultureInfo.Get­Cultures. To get associated specific culture use static method CultureInfo.Cre­ateSpecificCul­ture.

Following code is modified MSDN example.

Code:
// get all culture names
List list = new List();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
  string cultureName = "(none)";
  try { cultureName = CultureInfo.CreateSpecificCulture(ci.Name).Name; } catch { }
  list.Add(String.Format("{0,-10}{1,-10}{2}", ci.Name, cultureName, ci.EnglishName));
}

list.Sort();  // sort by name

// write to console
Console.WriteLine("CULTURE   SPEC.CULTURE  ENGLISH NAME");
Console.WriteLine("--------------------------------------------------------------");
foreach (string str in list)
  Console.WriteLine(str);


Execute the aboe code and get all culture names.

 If you feel this is helpful or you like it, Please share this using share buttons available on page.

2 comments :