gpt4 book ai didi

c# - if else 或 switch 的当前 CultureName?

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

我需要一个 if 或 switch 语句当前名称。我找不到解决方案。

此代码无效。

        if (Thread.CurrentThread.CurrentCulture == new CultureInfo("en"))
{
// EN (default)
}

if (Thread.CurrentThread.CurrentCulture == new CultureInfo("de"))
{
// DE
}

最佳答案

取决于你所说的“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")) {
...
}

关于c# - if else 或 switch 的当前 CultureName?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32254130/

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