.NET Chinese CultureInfo “zh” does not exist?

懵懂的女人 提交于 2019-12-13 19:09:53

问题


I'm using .NET 3.5 and running the following code:

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

I got the string "zh" from an xml:lang attribute. I don't understand why an exception is thrown, because for instance "de" (wich is parent for "de-DE") is working fine. The culture "zh-CN" does work, but thats nothing that I can use.

Edit: It works on .NET 4.5.1 (thanks to xanatos) - so even if the MSDN page explains that Chinese is an exception, the behaviour is different in newer .NET versions.


回答1:


There is a small note on the CultureInfo page:

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.

So you could try zh-Hans or zh-Hant

And/or you could see What cultures are supported by the CultureInfo class in .NET 3.5?

The accepted answer says:

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




回答2:


In .NET 3.5 "zh" does not work, use "zh-Hans" or "zh-Hant" instead. Didn't find a better solution. Or switch to .NET 4.5.



来源:https://stackoverflow.com/questions/28987368/net-chinese-cultureinfo-zh-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!