CultureInfo.GetCultures(CultureTypes) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得支援的文化特性清單,此清單經過指定的 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()
參數
- types
- CultureTypes
列舉值的位元組合,這些值可篩選要擷取的文化特性。
傳回
包含 types
參數所指定之文化特性的陣列。 文化特性陣列是未排序的。
例外狀況
types
指定了 CultureTypes 值的無效組合。
範例
下列程式代碼範例會顯示中性文化特性的數個屬性。
注意
此範例會分別顯示 zh-CHS
具有0x0004和0x7C04文化特性標識碼的和 zh-CHT
文化特性。 不過,您的 Windows Vista 應用程式應該使用 zh-Hans
名稱,而不是 zh-CHS
名稱 zh-Hant
,而不是 zh-CHT。 zh-Hans
和 zh-Hant
名稱代表目前的標準,除非您有使用舊名稱的原因,否則應該使用 。
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
備註
方法 GetCultures 最常呼叫, types
並將 參數設定為下列值:
SpecificCultures,它會傳回所有特定文化特性。
NeutralCultures,它會傳回所有中性文化特性和不因文化特性而異。
AllCultures,它會傳回所有中性和特定文化特性、安裝在 Windows 系統中的文化特性,以及使用者所建立的自定義文化特性。
UserCustomCulture,它會傳回所有自定義文化特性,例如 類別所 CultureAndRegionInfoBuilder 註冊的文化特性。 在 Windows 10 之前的 Windows 版本中,值UserCustomCulture會套用至所有使用者自定義文化特性。 從 Windows 10 開始,它會套用至缺少完整文化數據且沒有唯一本機標識符的系統文化特性,如屬性值所示LCID。 因此,下列程式代碼會在 Windows 10 和舊版 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