为什么不是所有的国家都在presented在CultureInfo.GetCultures()?有的、都在、不是、国家

由网友(积攒一身酷)分享简介:我使用的这个标准$ C $下填充国家清单:I am using this standard code for populating list of countries:static void Main(string[] args){List cultureList = new List();CultureInfo...

我使用的这个标准$ C $下填充国家清单:

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?

推荐答案

CultureInfo.GetCultures 是不可以设计在世界上所有的文化的完整和明确的清单。它的只有的设计,让您可以在电脑上找到的文化。

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的文档说:

记住,区域性名称和标识符再$ P $只有psent   文化的子集可在特定的计算机上找到。视窗   版本或服务包可以改变现有的文化。   应用程序添加使用CultureAndRegionInfoBuilder定制文化   类。用户添加使用Microsoft区域设置自己的定制文化   Builder工具。微软区域设置生成器是写在管理code   使用CultureAndRegionInfoBuilder类。

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.

在MSDN链接,可能是有用的:

Notes

关于数字一 один ,你需要知道些啥 YCC字幕

Links on the MSDN that may be usefull:

predefined RegionInfo列表:http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo(VS.80).aspx 如何创建自定义文化:http://msdn.microsoft.com/en-us/library/ms172469(VS.80).aspx 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

和的方式,可以缩短你的code用一个简单的LINQ'命令':

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();
阅读全文

相关推荐

最新文章