我需要if或switch语句当前名称。我找不到解决方案。
此代码不起作用。
if (Thread.CurrentThread.CurrentCulture == new CultureInfo("en"))
{
// EN (default)
}
if (Thread.CurrentThread.CurrentCulture == new CultureInfo("de"))
{
// DE
}
答案 0 :(得分:4)
取决于您的意思" CultureName "
// "ru-RU" on my workstation: Russian language (Russia dialect/subculture)
String name = Thread.CurrentThread.CurrentCulture.Name;
// "ru" - just Russian
String isoName = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
所以在你的情况下
// German, Germany (and not Austria)
if (Thread.CurrentThread.CurrentCulture.Name.Equals("de-DE")) {
...
}
else if (Thread.CurrentThread.CurrentCulture.Name.Equals("de-AT")) {
// German, but Austrian subculture
...
}
或
// German, any subculture, dialect ect.
if (Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Equals("de")) {
...
}