c# - .NET中文CultureInfo "zh"不存在?

标签 c# cultureinfo chinese-locale

我正在使用 .NET 3.5 并运行以下代码:

var culture = new CultureInfo("zh"); // Throws ArgumentException

我从 xml:lang 属性中得到字符串“zh”。我不明白为什么会抛出异常,因为例如“de”(“de-DE”的父级)工作正常。文化“zh-CN”确实有效,但那不是我可以使用的。

编辑: 它适用于 .NET 4.5.1(感谢 xanatos)——因此即使 MSDN 页面解释说中文是一个异常(exception),但在较新的 .NET 版本中行为是不同的。

最佳答案

CultureInfo上有个小纸条页:

There are two culture names that contradict this rule. The cultures Chinese (Simplified), named zh-Hans, and Chinese (Traditional), named zh-Hant, are neutral cultures. The culture names represent the current standard and should be used unless you have a reason for using the older names zh-CHS and zh-CHT.

所以你可以试试 zh-Hanszh-Hant

和/或您可以看到 What cultures are supported by the CultureInfo class in .NET 3.5?

接受的答案是:

Unfortunately, it is OS dependent. Check here for default language support per OS.

关于c# - .NET中文CultureInfo "zh"不存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28987368/

相关文章:

c# - .NET 相当于 Delphi 的 forceDirectory

c# - 如何获取 SQL CLR 程序集中发生的异常的堆栈跟踪

XmlElement 的 C# 数组正在添加另一层嵌套

c# - 格式未在法国文化中应用

c# - 以美国文化格式显示货币值

python - 如何在斯坦福中文解析器中不将英语拆分成单独的字母

c# - EntityFramework 核心单元测试 - SQLite 内存模式与 InMemory 提供程序

c# - 在给定文化的字符串中查找不区分大小写的第一个差异

mysql - 比MySQL字段长的汉字字符串

PHP gettext 支持简体中文吗?