CultureInfo.GetCultures(CultureTypes) Metodo

Definizione

Ottiene l'elenco delle impostazioni cultura supportate filtrate dal parametro CultureTypes specificato.Gets the list of supported cultures filtered by the specified CultureTypes parameter.

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()

Parametri

types
CultureTypes

Combinazione bit per bit dei valori di enumerazione che filtrano le impostazioni cultura da recuperare.A bitwise combination of the enumeration values that filter the cultures to retrieve.

Restituisce

Matrice che contiene le impostazioni cultura specificate dal parametro types.An array that contains the cultures specified by the types parameter. La matrice delle impostazioni cultura non è ordinata.The array of cultures is unsorted.

Eccezioni

types specifica una combinazione di valori CultureTypes non valida.types specifies an invalid combination of CultureTypes values.

Esempi

Nell'esempio di codice seguente vengono visualizzate diverse proprietà delle impostazioni cultura non associate ad alcun paese.The following code example displays several properties of the neutral cultures.

Nota

Nell'esempio vengono visualizzate le impostazioni cultura zh-CHS e zh-CHT con gli identificatori delle impostazioni cultura 0x0004 e 0x7C04, rispettivamente.The example displays the zh-CHS and zh-CHT cultures with the 0x0004 and 0x7C04 culture identifiers, respectively. Tuttavia, le applicazioni Windows Vista devono usare il nome zh-Hans anziché zh-CHS e il nome zh-Hant anziché zh-CHT.However, your Windows Vista applications should use the zh-Hans name instead of zh-CHS and the zh-Hant name instead of zh-CHT. I nomi zh-Hans e zh-Hant rappresentano lo standard corrente e devono essere usati a meno che non esista un motivo per usare i nomi precedenti.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.

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

Commenti

Il metodo GetCultures viene comunemente chiamato con il parametro types impostato sui valori seguenti:The GetCultures method is most commonly called with the types parameter set to the following values:

  • SpecificCultures, che restituisce tutte le impostazioni cultura specifiche.SpecificCultures, which returns all specific cultures.

  • NeutralCultures, che restituisce tutte le impostazioni cultura non associate ad alcun paese e le impostazioni cultura invarianti.NeutralCultures, which returns all neutral cultures and the invariant culture.

  • AllCultures, che restituisce tutte le impostazioni cultura neutre e specifiche, le impostazioni cultura installate nel sistema Windows e le impostazioni cultura personalizzate create dall'utente.AllCultures, which returns all neutral and specific cultures, cultures installed in the Windows system, and custom cultures created by the user.

  • UserCustomCulture, che restituisce tutte le impostazioni cultura personalizzate, ad esempio quelle registrate dalla classe CultureAndRegionInfoBuilder.UserCustomCulture, which returns all custom cultures, such as those registered by the CultureAndRegionInfoBuilder class. Nelle versioni di Windows precedenti a Windows 10, il valore UserCustomCulture si applica a tutte le impostazioni cultura personalizzate definite dall'utente.In versions of Windows before Windows 10, the UserCustomCulture value applies to all user-defined custom cultures. A partire da Windows 10, si applica alle impostazioni cultura di sistema che non dispongono di dati culturali completi e che non dispongono di un identificatore locale univoco, come indicato dal valore della proprietà LCID.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. Di conseguenza, il codice simile al seguente restituirà risultati diversi quando viene eseguito in Windows 10 e in una versione precedente di Windows.As a result, code such as the following will return different results when run on Windows 10 and on an earlier version of 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
    

Si applica a

Vedi anche