Compartilhar via


CultureInfo.GetCultures(CultureTypes) Método

Definição

Obtém a lista de culturas com suporte filtradas por parâmetro CultureTypes especificado.

public:
 static cli::array <System::Globalization::CultureInfo ^> ^ GetCultures(System::Globalization::CultureTypes types);
public static System.Globalization.CultureInfo[] GetCultures (System.Globalization.CultureTypes types);
static member GetCultures : System.Globalization.CultureTypes -> System.Globalization.CultureInfo[]
Public Shared Function GetCultures (types As CultureTypes) As CultureInfo()

Parâmetros

types
CultureTypes

Uma combinação bit a bit dos valores de enumeração que filtram as culturas a serem recuperadas.

Retornos

Uma matriz que contém as culturas especificadas pelo parâmetro types. A matriz de culturas não está classificada.

Exceções

O types especifica uma combinação inválida de valores CultureTypes.

Exemplos

O exemplo de código a seguir exibe várias propriedades das culturas neutras.

Observação

O exemplo exibe as zh-CHS culturas e zh-CHT com os identificadores de cultura 0x0004 e 0x7C04, respectivamente. No entanto, seus aplicativos do Windows Vista devem usar o zh-Hans nome em vez de zh-CHS e o zh-Hant nome em vez de zh-CHT. Os zh-Hans nomes e zh-Hant representam o padrão atual e devem ser usados, a menos que você tenha um motivo para usar os nomes mais antigos.

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Displays several properties of the neutral cultures.
   Console::WriteLine( "CULTURE ISO ISO WIN DISPLAYNAME                              ENGLISHNAME" );
   System::Collections::IEnumerator^ enum0 = CultureInfo::GetCultures( CultureTypes::NeutralCultures )->GetEnumerator();
   while ( enum0->MoveNext() )
   {
      CultureInfo^ ci = safe_cast<CultureInfo^>(enum0->Current);
      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            

*/
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

*/
Imports System.Globalization

Module Module1

   Public Sub Main()

      ' Displays several properties of the neutral cultures.
      Console.WriteLine("CULTURE ISO ISO WIN DISPLAYNAME                              ENGLISHNAME")
      Dim ci As CultureInfo
      For Each 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)
      Next ci

   End Sub



'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            

End Module

Comentários

O GetCultures método é mais comumente chamado com o types parâmetro definido para os seguintes valores:

  • SpecificCultures, que retorna todas as culturas específicas.

  • NeutralCultures, que retorna todas as culturas neutras e a cultura invariável.

  • AllCultures, que retorna todas as culturas neutras e específicas, culturas instaladas no sistema Windows e culturas personalizadas criadas pelo usuário.

  • UserCustomCulture, que retorna todas as culturas personalizadas, como aquelas registradas pela CultureAndRegionInfoBuilder classe . Em versões do Windows antes de Windows 10, o UserCustomCulture valor se aplica a todas as culturas personalizadas definidas pelo usuário. A partir do Windows 10, ele se aplica a culturas do sistema que não têm dados culturais completos e que não têm um identificador local exclusivo, conforme indicado pelo valor da LCID propriedade. Como resultado, código como o seguinte retornará resultados diferentes quando executado em Windows 10 e em uma versão anterior do Windows.

    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
    
    Imports System.Globalization
    
    Module Example
       Sub Main()
           Dim cultures() As CultureInfo = CultureInfo.GetCultures(CultureTypes.UserCustomCulture Or
                                                                   CultureTypes.SpecificCultures)
          Dim ctr As Integer = 0
          For Each culture In cultures
             If (culture.CultureTypes And CultureTypes.UserCustomCulture) = CultureTypes.UserCustomCulture Then
                ctr += 1
             End If
          Next
          Console.WriteLine("Number of Specific Custom Cultures: {0}", ctr)
       End Sub
    End Module
    ' 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
    

Aplica-se a

Confira também