if else 或 switch 的当前 CultureName?

Current CultureName for if else or a switch?

我需要当前名称的 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")) {
    ...
  }