Bagikan melalui


CultureInfo.GetCultures(CultureTypes) Metode

Definisi

Mendapatkan daftar budaya yang didukung yang difilter oleh parameter yang ditentukan CultureTypes .

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

Parameter

types
CultureTypes

Kombinasi bitwise dari nilai enumerasi yang memfilter budaya untuk diambil.

Mengembalikan

Array yang berisi budaya yang ditentukan oleh types parameter . Array budaya tidak diurungkan.

Pengecualian

types menentukan kombinasi CultureTypes nilai yang tidak valid.

Contoh

Contoh kode berikut menampilkan beberapa properti budaya netral.

Catatan

Contohnya menampilkan zh-CHS budaya dan zh-CHT dengan pengidentifikasi budaya 0x0004 dan 0x7C04. Namun, aplikasi Windows Vista Anda harus menggunakan zh-Hans nama alih-alih zh-CHS dan zh-Hant nama alih-alih zh-CHT. Nama zh-Hans dan zh-Hant mewakili standar saat ini, dan harus digunakan kecuali Anda memiliki alasan untuk menggunakan nama yang lebih lama.

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

Keterangan

Metode GetCultures ini paling umum disebut dengan parameter yang types diatur ke nilai berikut:

  • SpecificCultures, yang mengembalikan semua budaya tertentu.

  • NeutralCultures, yang mengembalikan semua budaya netral dan budaya invarian.

  • AllCultures, yang mengembalikan semua budaya netral dan spesifik, budaya yang diinstal dalam sistem Windows, dan budaya kustom yang dibuat oleh pengguna.

  • UserCustomCulture, yang mengembalikan semua budaya kustom, seperti yang terdaftar oleh CultureAndRegionInfoBuilder kelas . Dalam versi Windows sebelum Windows 10, UserCustomCulture nilai berlaku untuk semua budaya kustom yang ditentukan pengguna. Dimulai dengan Windows 10, itu berlaku untuk budaya sistem yang tidak memiliki data budaya lengkap dan yang tidak memiliki pengidentifikasi lokal yang unik, seperti yang ditunjukkan LCID oleh nilai properti. Akibatnya, kode seperti berikut ini akan mengembalikan hasil yang berbeda saat dijalankan pada Windows 10 dan pada versi Windows yang lebih lama.

    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
    

Berlaku untuk

Lihat juga