gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 21:23:26 24 4
gpt4 key购买 nike

我正在使用 .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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com