0

Does CultureInfo.CurrentCulture.Name always return the language code and country/region code separated by a hyphen? I have been told that CultureInfo.CurrentCulture.Name can sometimes return just the two letter language code, but I have found no documentation to substantiate this claim.

cpdev
  • 27
  • 4
  • Here are some relevant links to help https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.name?view=net-6.0#remarks https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c – Ric Sep 23 '22 at 12:36
  • If it's a neutral Culture, then yes. What are you looking for? – Jimi Sep 23 '22 at 12:45
  • I don't understand the down vote. Regarding what is returned by CultureInfo.CurrentCulture.Name, the official Microsoft documentation DOES NOT mention what CultureInfo.CurrentCulture.Name returns if using a neutral culture value. You have to look carefully at the example further down in the documentation to determine that only the two-character neutral culture value is returned if the CultureInfo object is created using a neutral culture string. – cpdev Sep 23 '22 at 14:56

1 Answers1

0

Thank you Jimi for your reference to neutral culture. I found the following example that demonstrating a neutral culture, where only "fr" is specified, and therefore CultureInfo.CurrentCulture.Name will only return the two-character language code:

   public static void Main()
   {
      double value = 1634.92;
      CultureInfo.CurrentCulture = new CultureInfo("fr-CA");
      Console.WriteLine("Current Culture: {0}",
                        CultureInfo.CurrentCulture.Name);
      Console.WriteLine("{0:C2}\n", value);

      Thread.CurrentThread.CurrentCulture = new CultureInfo("fr");
      Console.WriteLine("Current Culture: {0}",
                        CultureInfo.CurrentCulture.Name);
      Console.WriteLine("{0:C2}", value);
   }


// The example displays the following output:
//       Current Culture: fr-CA
//       1 634,92 $
//
//       Current Culture: fr
//       1 634,92 €
cpdev
  • 27
  • 4