I am using this standard code for populating list of countries:
static void Main(string[] args)
{
List cultureList = new List();
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
foreach (CultureInfo culture in cultures)
{
try
{
RegionInfo region = new RegionInfo(culture.LCID);
if (!(cultureList.Contains(region.EnglishName)))
{
cultureList.Add(region.EnglishName);
Console.WriteLine(region.EnglishName);
}
}
catch (ArgumentException ex)
{
// just ignore this
continue;
}
}
}
I saw that some countries are missed. Just wondered what's the reason of such situation?
Provides information about a specific culture (called a locale for unmanaged code development). The information includes the names for the culture, the writing system, the calendar used, the sort order of strings, and formatting for dates and numbers.
The CultureInfo class provides culture-specific information, such as the language, sublanguage, country/region, calendar, and conventions associated with a particular culture. This class also provides access to culture-specific instances of the DateTimeFormatInfo, NumberFormatInfo, CompareInfo, and TextInfo objects.
The CultureInfo. CurrentCulture property is a per-thread setting; that is, each thread can have its own culture. You get the culture of the current thread by retrieving the value of the CultureInfo. CurrentCulture property, as the following example illustrates. C# Copy.
CultureInfo.GetCultures
is not designed to be a complete and definitive list of all the cultures in the world. It's only designed to get you the cultures that can be found on the computer.
CultureInfo documentation says:
Remember that the culture names and identifiers represent only a subset of cultures that can be found on a particular computer. Windows versions or service packs can change the available cultures. Applications add custom cultures using the CultureAndRegionInfoBuilder class. Users add their own custom cultures using the Microsoft Locale Builder tool. Microsoft Locale Builder is written in managed code using the CultureAndRegionInfoBuilder class.
Links on the MSDN that may be usefull:
And by the way, you can shorten your code with a simple LINQ 'command':
var regionInfos = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
.Select(c => new RegionInfo(c.LCID))
.Distinct()
.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With