Why not all countries are presented in CultureInfo.GetCultures()?

前端 未结 3 759
南方客
南方客 2020-12-20 12:39

I am using this standard code for populating list of countries:

static void Main(string[] args)
{
    List cultureList = new List();

    CultureInfo[] cultu         


        
3条回答
  •  青春惊慌失措
    2020-12-20 13:31

    The answer is: By design

    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.


    Notes

    Links on the MSDN that may be usefull:

    • Predefined RegionInfo list: http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo(VS.80).aspx
    • How to create custom Cultures: http://msdn.microsoft.com/en-us/library/ms172469(VS.80).aspx

    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();
    

提交回复
热议问题