为什么不是所有的国家都在presented在CultureInfo.GetCultures()? [英] Why not all countries are presented in CultureInfo.GetCultures()?

查看:207
本文介绍了为什么不是所有的国家都在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[] 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

Links on the MSDN that may be usefull:

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

这篇关于为什么不是所有的国家都在presented在CultureInfo.GetCultures()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆