CultureInfo 類別

定義

提供有關特定文化特性 (Culture) 的資訊 (文化特性在 Unmanaged 程式碼開發中稱為「地區設定」(Locale))。 這項資訊包含文化特性的名稱、書寫系統、使用的曆法、字串的排序次序,以及日期和數字的格式。

public ref class CultureInfo : IFormatProvider
public ref class CultureInfo : ICloneable, IFormatProvider
public class CultureInfo : IFormatProvider
public class CultureInfo : ICloneable, IFormatProvider
[System.Serializable]
public class CultureInfo : ICloneable, IFormatProvider
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class CultureInfo : ICloneable, IFormatProvider
type CultureInfo = class
    interface IFormatProvider
type CultureInfo = class
    interface ICloneable
    interface IFormatProvider
[<System.Serializable>]
type CultureInfo = class
    interface ICloneable
    interface IFormatProvider
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type CultureInfo = class
    interface ICloneable
    interface IFormatProvider
Public Class CultureInfo
Implements IFormatProvider
Public Class CultureInfo
Implements ICloneable, IFormatProvider
繼承
CultureInfo
屬性
實作

範例

下列範例示範如何使用 CultureInfo 國際排序建立西班牙文 (西班牙) 的物件,以及另一個 CultureInfo 具有傳統排序的物件。

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;
int main()
{
   
   // Creates and initializes the CultureInfo which uses the international sort.
   CultureInfo^ myCIintl = gcnew CultureInfo( "es-ES",false );
   
   // Creates and initializes the CultureInfo which uses the traditional sort.
   CultureInfo^ myCItrad = gcnew CultureInfo( 0x040A,false );
   
   // Displays the properties of each culture.
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL" );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "CompareInfo", myCIintl->CompareInfo, myCItrad->CompareInfo );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "DisplayName", myCIintl->DisplayName, myCItrad->DisplayName );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "EnglishName", myCIintl->EnglishName, myCItrad->EnglishName );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "IsNeutralCulture", myCIintl->IsNeutralCulture, myCItrad->IsNeutralCulture );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "IsReadOnly", myCIintl->IsReadOnly, myCItrad->IsReadOnly );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "LCID", myCIintl->LCID, myCItrad->LCID );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "Name", myCIintl->Name, myCItrad->Name );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "NativeName", myCIintl->NativeName, myCItrad->NativeName );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "Parent", myCIintl->Parent, myCItrad->Parent );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "TextInfo", myCIintl->TextInfo, myCItrad->TextInfo );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "ThreeLetterISOLanguageName", myCIintl->ThreeLetterISOLanguageName, myCItrad->ThreeLetterISOLanguageName );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl->ThreeLetterWindowsLanguageName, myCItrad->ThreeLetterWindowsLanguageName );
   Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "TwoLetterISOLanguageName", myCIintl->TwoLetterISOLanguageName, myCItrad->TwoLetterISOLanguageName );
   Console::WriteLine();
   
   // Compare two strings using myCIintl -> 
   Console::WriteLine( "Comparing \"llegar\" and \"lugar\"" );
   Console::WriteLine( "   With myCIintl -> CompareInfo -> Compare: {0}", myCIintl->CompareInfo->Compare( "llegar", "lugar" ) );
   Console::WriteLine( "   With myCItrad -> CompareInfo -> Compare: {0}", myCItrad->CompareInfo->Compare( "llegar", "lugar" ) );
}

/*
This code produces the following output.

PROPERTY                       INTERNATIONAL                                  TRADITIONAL              
CompareInfo                    CompareInfo - es-ES                            CompareInfo - es-ES_tradnl
DisplayName                    Spanish (Spain)                                Spanish (Spain)          
EnglishName                    Spanish (Spain, International Sort)            Spanish (Spain, Traditional Sort)
IsNeutralCulture               False                                          False                    
IsReadOnly                     False                                          False                    
LCID                           3082                                           1034                     
Name                           es-ES                                          es-ES                    
NativeName                     Español (España, alfabetización internacional) Español (España, alfabetización tradicional)
Parent                         es                                             es                       
TextInfo                       TextInfo - es-ES                               TextInfo - es-ES_tradnl  
ThreeLetterISOLanguageName     spa                                            spa                      
ThreeLetterWindowsLanguageName ESN                                            ESP                      
TwoLetterISOLanguageName       es                                             es                       

Comparing "llegar" and "lugar"
   With myCIintl -> CompareInfo -> Compare: -1
   With myCItrad -> CompareInfo -> Compare: 1

*/
using System;
using System.Globalization;

public class SamplesCultureInfo
{
    public static void Main()
    {
        // Creates and initializes the CultureInfo which uses the international sort.
        CultureInfo myCIintl = new CultureInfo("es-ES", false);

        // Creates and initializes the CultureInfo which uses the traditional sort.
        CultureInfo myCItrad = new CultureInfo(0x040A, false);

        // Displays the properties of each culture.
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL");
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "CompareInfo", myCIintl.CompareInfo, myCItrad.CompareInfo);
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "DisplayName", myCIintl.DisplayName, myCItrad.DisplayName);
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "EnglishName", myCIintl.EnglishName, myCItrad.EnglishName);
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "IsNeutralCulture", myCIintl.IsNeutralCulture, myCItrad.IsNeutralCulture);
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "IsReadOnly", myCIintl.IsReadOnly, myCItrad.IsReadOnly);
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "LCID", myCIintl.LCID, myCItrad.LCID);
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "Name", myCIintl.Name, myCItrad.Name);
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "NativeName", myCIintl.NativeName, myCItrad.NativeName);
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "Parent", myCIintl.Parent, myCItrad.Parent);
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "TextInfo", myCIintl.TextInfo, myCItrad.TextInfo);
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.ThreeLetterISOLanguageName, myCItrad.ThreeLetterISOLanguageName);
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.ThreeLetterWindowsLanguageName, myCItrad.ThreeLetterWindowsLanguageName);
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "TwoLetterISOLanguageName", myCIintl.TwoLetterISOLanguageName, myCItrad.TwoLetterISOLanguageName);
        Console.WriteLine();

        // Compare two strings using myCIintl.
        Console.WriteLine("Comparing \"llegar\" and \"lugar\"");
        Console.WriteLine("   With myCIintl.CompareInfo.Compare: {0}", myCIintl.CompareInfo.Compare("llegar", "lugar"));
        Console.WriteLine("   With myCItrad.CompareInfo.Compare: {0}", myCItrad.CompareInfo.Compare("llegar", "lugar"));
    }
}

/*
This code produces the following output.

PROPERTY                       INTERNATIONAL                                  TRADITIONAL
CompareInfo                    CompareInfo - es-ES                            CompareInfo - es-ES_tradnl
DisplayName                    Spanish (Spain)                                Spanish (Spain)
EnglishName                    Spanish (Spain, International Sort)            Spanish (Spain, Traditional Sort)
IsNeutralCulture               False                                          False
IsReadOnly                     False                                          False
LCID                           3082                                           1034
Name                           es-ES                                          es-ES
NativeName                     Español (España, alfabetización internacional) Español (España, alfabetización tradicional)
Parent                         es                                             es
TextInfo                       TextInfo - es-ES                               TextInfo - es-ES_tradnl
ThreeLetterISOLanguageName     spa                                            spa
ThreeLetterWindowsLanguageName ESN                                            ESP
TwoLetterISOLanguageName       es                                             es

Comparing "llegar" and "lugar"
   With myCIintl.CompareInfo.Compare: -1
   With myCItrad.CompareInfo.Compare: 1

*/
Imports System.Collections
Imports System.Globalization

Module Module1

    Public Sub Main()

        ' Creates and initializes the CultureInfo which uses the international sort.
        Dim myCIintl As New CultureInfo("es-ES", False)

        ' Creates and initializes the CultureInfo which uses the traditional sort.
        Dim myCItrad As New CultureInfo(&H40A, False)

        ' Displays the properties of each culture.
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL")
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "CompareInfo", myCIintl.CompareInfo, myCItrad.CompareInfo)
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "DisplayName", myCIintl.DisplayName, myCItrad.DisplayName)
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "EnglishName", myCIintl.EnglishName, myCItrad.EnglishName)
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "IsNeutralCulture", myCIintl.IsNeutralCulture, myCItrad.IsNeutralCulture)
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "IsReadOnly", myCIintl.IsReadOnly, myCItrad.IsReadOnly)
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "LCID", myCIintl.LCID, myCItrad.LCID)
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "Name", myCIintl.Name, myCItrad.Name)
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "NativeName", myCIintl.NativeName, myCItrad.NativeName)
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "Parent", myCIintl.Parent, myCItrad.Parent)
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "TextInfo", myCIintl.TextInfo, myCItrad.TextInfo)
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.ThreeLetterISOLanguageName, myCItrad.ThreeLetterISOLanguageName)
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.ThreeLetterWindowsLanguageName, myCItrad.ThreeLetterWindowsLanguageName)
        Console.WriteLine("{0,-31}{1,-47}{2,-25}", "TwoLetterISOLanguageName", myCIintl.TwoLetterISOLanguageName, myCItrad.TwoLetterISOLanguageName)
        Console.WriteLine()

        ' Compare two strings using myCIintl.
        Console.WriteLine("Comparing ""llegar"" and ""lugar""")
        Console.WriteLine("   With myCIintl.CompareInfo.Compare: {0}", myCIintl.CompareInfo.Compare("llegar", "lugar"))
        Console.WriteLine("   With myCItrad.CompareInfo.Compare: {0}", myCItrad.CompareInfo.Compare("llegar", "lugar"))

    End Sub



'This code produces the following output.
'
'PROPERTY                       INTERNATIONAL                                  TRADITIONAL              
'CompareInfo                    CompareInfo - es-ES                            CompareInfo - es-ES_tradnl
'DisplayName                    Spanish (Spain)                                Spanish (Spain)          
'EnglishName                    Spanish (Spain, International Sort)            Spanish (Spain, Traditional Sort)
'IsNeutralCulture               False                                          False                    
'IsReadOnly                     False                                          False                    
'LCID                           3082                                           1034                     
'Name                           es-ES                                          es-ES                    
'NativeName                     Español (España, alfabetización internacional) Español (España, alfabetización tradicional)
'Parent                         es                                             es                       
'TextInfo                       TextInfo - es-ES                               TextInfo - es-ES_tradnl  
'ThreeLetterISOLanguageName     spa                                            spa                      
'ThreeLetterWindowsLanguageName ESN                                            ESP                      
'TwoLetterISOLanguageName       es                                             es                       
'
'Comparing "llegar" and "lugar"
'   With myCIintl.CompareInfo.Compare: -1
'   With myCItrad.CompareInfo.Compare: 1

End Module

備註

如需此 API 的詳細資訊,請參閱 CultureInfo 補充 API 備註

建構函式

CultureInfo(Int32)

根據文化特性識別項所指定的文化特性,初始化 CultureInfo 類別的新執行個體。

CultureInfo(Int32, Boolean)

根據文化特性識別碼所指定的文化特性,以及指定是否從 Windows 使用使用者選取的文化特性設定的值,初始化 類別的新實例 CultureInfo

CultureInfo(String)

根據名稱所指定的文化特性,初始化 CultureInfo 類別的新執行個體。

CultureInfo(String, Boolean)

根據名稱所指定的文化特性,以及指定是否從 Windows 使用使用者選取的文化特性設定的值,初始化 類別的新實例 CultureInfo

屬性

Calendar

取得文化特性使用的預設曆法。

CompareInfo

取得 CompareInfo,定義此文化特性如何比較字串。

CultureTypes

取得和目前 CultureInfo 物件關聯的文化特性類型。

CurrentCulture

取得或設定 CultureInfo 物件,表示目前線程和工作型異步操作所使用的文化特性。

CurrentUICulture

取得或設定 CultureInfo 物件,此物件代表 Resource Manager 用於執行階段查詢特定文化特性資源的目前使用者介面文化特性。

DateTimeFormat

取得或設定 DateTimeFormatInfo,定義日期和時間在文化特性上適當的顯示格式。

DefaultThreadCurrentCulture

取得或設定目前應用程式定義域中之執行緒的預設文化特性。

DefaultThreadCurrentUICulture

取得或設定目前應用程式定義域中之執行緒的預設 UI 文化特性。

DisplayName

取得完整當地語系化文化特性名稱。

EnglishName

以英文格式取得 languagefull [country/regionfull] 的文化特性名稱。

IetfLanguageTag

已取代。 取得語言的 RFC 4646 標準識別。

InstalledUICulture

取得 CultureInfo,代表作業系統所安裝的文化特性。

InvariantCulture

取得與文化特性無關的 (不變的) CultureInfo 物件。

IsNeutralCulture

取得值,指出目前 CultureInfo 是否代表中性文化特性。

IsReadOnly

取得值,指出目前 CultureInfo 是否唯讀。

KeyboardLayoutId

取得使用中的輸入地區設定識別項 (Input Locale Identifier)。

LCID

取得目前 CultureInfo 的文化特性識別項。

Name

取得 languagecode2country/regioncode2- 格式的文化特性名稱。

NativeName

取得文化特性設定為要顯示的文化特性名稱,由語言、國家/地區和選擇性 (Optional) 指令碼組成。

NumberFormat

取得或設定 NumberFormatInfo,定義數字、貨幣和百分比在文化特性上適當的顯示格式。

OptionalCalendars

取得可為文化特性所使用的曆法清單。

Parent

取得 CultureInfo,代表目前 CultureInfo 的父文化特性。

TextInfo

取得 TextInfo,定義與文化特性關聯的書寫系統。

ThreeLetterISOLanguageName

取得目前 CultureInfo 的語言的 ISO 639-2 三個字母代碼。

ThreeLetterWindowsLanguageName

取得 Windows API 中所定義之語言的三個字母代碼。

TwoLetterISOLanguageName

取得目前 CultureInfo語言的 ISO 639-1 雙字母或 ISO 639-3 三個字母代碼。

UseUserOverride

取得值,指出目前 CultureInfo 是否使用使用者選取的文化特性設定。

方法

ClearCachedData()

重新整理已快取的文化特性相關資訊。

Clone()

建立目前的 CultureInfo 複本。

CreateSpecificCulture(String)

建立 CultureInfo,代表與指定名稱相關的特定文化特性。

Equals(Object)

判斷指定物件是否與目前 CultureInfo 為相同的文化特性。

GetConsoleFallbackUICulture()

在預設的圖形使用者介面 (Graphic User Interface,GUI) 的文化特性不適合主控台應用程式 (Console Application) 時,取得適合的替代使用者介面文化特性。

GetCultureInfo(Int32)

使用指定的文化特性識別項,擷取已快取的唯讀文化特性執行個體。

GetCultureInfo(String)

使用指定的文化特性名稱,擷取已快取的唯讀文化特性執行個體。

GetCultureInfo(String, Boolean)

擷取文化特性的快取、唯讀執行個體。

GetCultureInfo(String, String)

擷取文化特性的快取、唯讀執行個體。 這些參數會指定文化特性,這個文化特性使用另一個文化特性所指定的 TextInfoCompareInfo 物件來初始化。

GetCultureInfoByIetfLanguageTag(String)

已取代。 擷取唯讀的 CultureInfo 物件,其語言特性是透過指定的 RFC 4646 語言標籤所辨識。

GetCultures(CultureTypes)

取得支援的文化特性清單,此清單經過指定的 CultureTypes 參數篩選。

GetFormat(Type)

取得定義如何格式化指定類型的物件。

GetHashCode()

做為目前 CultureInfo 的雜湊函式,適用於雜湊演算法與資料結構,例如雜湊表。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ReadOnly(CultureInfo)

傳回指定 CultureInfo 物件的唯讀包裝函式。

ToString()

傳回字串,其中包含格式為 languagecode2country/regioncode2- 的目前 CultureInfo 名稱。

適用於

另請參閱