TwoLetterISOLanguageName Property

CultureInfo.TwoLetterISOLanguageName Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets the ISO 639-1 two-letter code for the language of the current CultureInfo.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

public virtual string TwoLetterISOLanguageName { get; }

Property Value

Type: System.String
The ISO 639-1 two-letter code for the language of the current CultureInfo object.

For example, the two-letter abbreviation for English is "en". For the invariant culture, the TwoLetterISOLanguageName property returns the string "iv".

The following example displays the value of the TwoLetterISOLanguageName property for selected cultures. It then uses this value to instantiate a CultureInfo object, which it compares with the parent culture returned by the selected culture's Parent property. As the output shows, in most cases these two CultureInfo objects are equal. (The exact output may vary, depending on the platform on which the example is run.)


using System;
using System.Globalization;
using System.Threading;

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Define an array of selected culture names.
      string[] cultureCodes = {"ar-JO", "ar-SY", "az-Cyrl-AZ", "az-Latn-AZ", "zh-CN", 
                               "zh-SG", "zh-TW", "nl-BE", "nl-NL", "en-BZ", "en-CA", 
                               "en-NZ", "en-GB", "en-US", "fr-BE", "fr-CA", "fr-FR", 
                               "de-AT", "de-DE", "de-CH", "it-IT", "it-CH", "ms-BN",
                               "ms-MY", "nb-NO", "nn-NO", "pt-BR", "pt-PT", "sr-Cyrl-CS", 
                               "sr-Latn-CS", "es-AR", "es-DO", "es-MX", "es-ES", 
                               "es-ES_tradnl", "sv-FI", "sv-SE", "uz-Cyrl-UZ", "uz-Latn-UZ"};
      string exCultureName = null;

      // Iterate array and create a CultureInfo object for each culture name.
      foreach (string cultureCode in cultureCodes)
      {
         try {
            exCultureName = cultureCode;
            outputBlock.Text += String.Format("{0}: ", cultureCode);
            CultureInfo ci = new CultureInfo(cultureCode);
            // Get this culture's parent.
            CultureInfo cip = ci.Parent;
            outputBlock.Text += String.Format("Parent is {0}, ", cip.Name);
            // Get the culture's two-letter language name.
            string isoName = ci.TwoLetterISOLanguageName;
            outputBlock.Text += String.Format("Language name is '{0}', ", isoName);
            // Instantiate the neutral culture using the two-letter language name.
            exCultureName = isoName;
            CultureInfo ciNeutral = new CultureInfo(isoName);

            // Determine whether the parent object equals the neutral culture.
            outputBlock.Text += String.Format("Equality: {0}\n", 
                                              cip.Equals(ciNeutral));
         }
         catch (ArgumentException) {
            outputBlock.Text += String.Format("Unable to instantiate culture '{0}'.\n", exCultureName);
         }
      }
   }
}
// The example displays the following output:
//    ar-JO: Parent is ar, Language name is 'ar', Equality: True
//    ar-SY: Parent is ar, Language name is 'ar', Equality: True
//    az-Cyrl-AZ: Parent is az, Language name is 'az', Equality: True
//    az-Latn-AZ: Parent is az, Language name is 'az', Equality: True
//    zh-CN: Parent is zh-Hans, Language name is 'zh', Unable to instantiate culture 'zh'.
//    zh-SG: Parent is zh-Hans, Language name is 'zh', Unable to instantiate culture 'zh'.
//    zh-TW: Parent is zh-Hant, Language name is 'zh', Unable to instantiate culture 'zh'.
//    nl-BE: Parent is nl, Language name is 'nl', Equality: True
//    nl-NL: Parent is nl, Language name is 'nl', Equality: True
//    en-BZ: Parent is en, Language name is 'en', Equality: True
//    en-CA: Parent is en, Language name is 'en', Equality: True
//    en-NZ: Parent is en, Language name is 'en', Equality: True
//    en-GB: Parent is en, Language name is 'en', Equality: True
//    en-US: Parent is en, Language name is 'en', Equality: True
//    fr-BE: Parent is fr, Language name is 'fr', Equality: True
//    fr-CA: Parent is fr, Language name is 'fr', Equality: True
//    fr-FR: Parent is fr, Language name is 'fr', Equality: True
//    de-AT: Parent is de, Language name is 'de', Equality: True
//    de-DE: Parent is de, Language name is 'de', Equality: True
//    de-CH: Parent is de, Language name is 'de', Equality: True
//    it-IT: Parent is it, Language name is 'it', Equality: True
//    it-CH: Parent is it, Language name is 'it', Equality: True
//    ms-BN: Parent is ms, Language name is 'ms', Equality: True
//    ms-MY: Parent is ms, Language name is 'ms', Equality: True
//    nb-NO: Parent is no, Language name is 'nb', Unable to instantiate culture 'nb'.
//    nn-NO: Parent is no, Language name is 'nn', Unable to instantiate culture 'nn'.
//    pt-BR: Parent is pt, Language name is 'pt', Equality: True
//    pt-PT: Parent is pt, Language name is 'pt', Equality: True
//    sr-Cyrl-CS: Parent is , Language name is 'sr', Unable to instantiate culture 'sr'.
//    sr-Latn-CS: Parent is , Language name is 'sr', Unable to instantiate culture 'sr'.
//    es-AR: Parent is es, Language name is 'es', Equality: True
//    es-DO: Parent is es, Language name is 'es', Equality: True
//    es-MX: Parent is es, Language name is 'es', Equality: True
//    es-ES: Parent is es, Language name is 'es', Equality: True
//    es-ES_tradnl: Parent is es, Language name is 'es', Equality: True
//    sv-FI: Parent is sv, Language name is 'sv', Equality: True
//    sv-SE: Parent is sv, Language name is 'sv', Equality: True
//    uz-Cyrl-UZ: Parent is uz, Language name is 'uz', Equality: True
//    uz-Latn-UZ: Parent is uz, Language name is 'uz', Equality: True


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2016 Microsoft