问题
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