CultureInfo.GetCultures(CultureTypes) Method

Definition

Gets the list of supported cultures filtered by the specified CultureTypes parameter.

C#
public static System.Globalization.CultureInfo[] GetCultures (System.Globalization.CultureTypes types);

Parameters

types
CultureTypes

A bitwise combination of the enumeration values that filter the cultures to retrieve.

Returns

An array that contains the cultures specified by the types parameter. The array of cultures is unsorted.

Exceptions

types specifies an invalid combination of CultureTypes values.

Examples

The following code example displays several properties of the neutral cultures.

Note

The example displays the zh-CHS and zh-CHT cultures with the 0x0004 and 0x7C04 culture identifiers, respectively. However, your Windows Vista applications should use the zh-Hans name instead of zh-CHS and the zh-Hant name instead of zh-CHT. The zh-Hans and zh-Hant names represent the current standard, and should be used unless you have a reason for using the older names.

C#
using System;
using System.Globalization;

public class SamplesCultureInfo
{

   public static void Main()
   {

      // Displays several properties of the neutral cultures.
      Console.WriteLine("CULTURE ISO ISO WIN DISPLAYNAME                              ENGLISHNAME");
      foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
      {
         Console.Write("{0,-7}", ci.Name);
         Console.Write(" {0,-3}", ci.TwoLetterISOLanguageName);
         Console.Write(" {0,-3}", ci.ThreeLetterISOLanguageName);
         Console.Write(" {0,-3}", ci.ThreeLetterWindowsLanguageName);
         Console.Write(" {0,-40}", ci.DisplayName);
         Console.WriteLine(" {0,-40}", ci.EnglishName);
      }
   }
}


/*
This code produces the following output.  This output has been cropped for brevity.

CULTURE ISO ISO WIN DISPLAYNAME                              ENGLISHNAME
ar      ar  ara ARA Arabic                                   Arabic
bg      bg  bul BGR Bulgarian                                Bulgarian
ca      ca  cat CAT Catalan                                  Catalan
zh-Hans zh  zho CHS Chinese (Simplified)                     Chinese (Simplified)
cs      cs  ces CSY Czech                                    Czech
da      da  dan DAN Danish                                   Danish
de      de  deu DEU German                                   German
el      el  ell ELL Greek                                    Greek
en      en  eng ENU English                                  English
es      es  spa ESP Spanish                                  Spanish
fi      fi  fin FIN Finnish                                  Finnish
zh      zh  zho CHS Chinese                                  Chinese
zh-Hant zh  zho CHT Chinese (Traditional)                    Chinese (Traditional)
zh-CHS  zh  zho CHS Chinese (Simplified) Legacy              Chinese (Simplified) Legacy
zh-CHT  zh  zho CHT Chinese (Traditional) Legacy             Chinese (Traditional) Legacy

*/

Remarks

The GetCultures method is most commonly called with the types parameter set to the following values:

  • SpecificCultures, which returns all specific cultures.

  • NeutralCultures, which returns all neutral cultures and the invariant culture.

  • AllCultures, which returns all neutral and specific cultures, cultures installed in the Windows system, and custom cultures created by the user.

  • UserCustomCulture, which returns all custom cultures, such as those registered by the CultureAndRegionInfoBuilder class. In versions of Windows before Windows 10, the UserCustomCulture value applies to all user-defined custom cultures. Starting with Windows 10, it applies to system cultures that lack complete cultural data and that do not have a unique local identifier, as indicated by the LCID property value. As a result, code such as the following will return different results when run on Windows 10 and on an earlier version of Windows.

    C#
    using System;
    using System.Globalization;
    
    public class Example
    {
       public static void Main()
       {
           CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.UserCustomCulture |
                                                            CultureTypes.SpecificCultures);
          int ctr = 0;
          foreach (var culture in cultures)
             if ((culture.CultureTypes & CultureTypes.UserCustomCulture) == CultureTypes.UserCustomCulture)
                ctr++;
    
          Console.WriteLine("Number of Specific Custom Cultures: {0}", ctr);
       }
    }
    // If run under Windows 8, the example displays output like the following:
    //      Number of Specific Custom Cultures: 6
    // If run under Windows 10, the example displays output like the following:
    //      Number of Specific Custom Cultures: 279
    

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also