CultureInfo.GetCultureInfo 方法

定義

擷取文化特性的快取、唯讀執行個體。Retrieves a cached, read-only instance of a culture.

多載

GetCultureInfo(Int32)

使用指定的文化特性識別項,擷取已快取的唯讀文化特性執行個體。Retrieves a cached, read-only instance of a culture by using the specified culture identifier.

GetCultureInfo(String)

使用指定的文化特性名稱,擷取已快取的唯讀文化特性執行個體。Retrieves a cached, read-only instance of a culture using the specified culture name.

GetCultureInfo(String, String)

擷取文化特性的快取、唯讀執行個體。Retrieves a cached, read-only instance of a culture. 這些參數會指定文化特性,這個文化特性使用另一個文化特性所指定的 TextInfoCompareInfo 物件來初始化。Parameters specify a culture that is initialized with the TextInfo and CompareInfo objects specified by another culture.

GetCultureInfo(Int32)

使用指定的文化特性識別項,擷取已快取的唯讀文化特性執行個體。Retrieves a cached, read-only instance of a culture by using the specified culture identifier.

public:
 static System::Globalization::CultureInfo ^ GetCultureInfo(int culture);
public static System.Globalization.CultureInfo GetCultureInfo (int culture);
static member GetCultureInfo : int -> System.Globalization.CultureInfo
Public Shared Function GetCultureInfo (culture As Integer) As CultureInfo

參數

culture
Int32

地區設定識別項 (LCID)。A locale identifier (LCID).

傳回

唯讀 CultureInfo 物件。A read-only CultureInfo object.

例外狀況

culture 小於零。culture is less than zero.

culture 指定不支援的文化特性 (Culture)。culture specifies a culture that is not supported. 如需詳細資訊,請參閱<呼叫者注意事項>一節。See the Notes to Caller section for more information.

備註

建議您使用此方法的字串多載(GetCultureInfo(String)),因為應該使用地區設定名稱來取代 Lcid。We recommend that you use the string overload of this method (GetCultureInfo(String)), because locale names should be used instead of LCIDs. 若為自訂地區設定,則需要地區設定名稱。For custom locales, the locale name is required.

如果 culture 是目前文化特性的地區設定識別碼,則傳回的 CultureInfo 物件不會反映任何使用者覆寫。If culture is the locale identifier of the current culture, the returned CultureInfo object does not reflect any user overrides.

給呼叫者的注意事項

如果 culture 不是有效的文化特性識別碼,.NET Framework 3.5.NET Framework 3.5 和較早的版本會擲回 ArgumentExceptionThe .NET Framework 3.5.NET Framework 3.5 and earlier versions throw an ArgumentException if culture is not a valid culture identifier. .NET Framework 4.NET Framework 4開始,這個方法會擲回 CultureNotFoundExceptionStarting with the .NET Framework 4.NET Framework 4, this method throws a CultureNotFoundException. 從在 Windows 7 或更新版本的 .NET Framework 4.NET Framework 4 或更新版本下執行的應用程式開始,方法會嘗試取出 CultureInfo 物件,其識別碼是從作業系統 culture 的,如果作業系統不支援該文化特性,方法會擲回 CultureNotFoundExceptionStarting with apps that run under the .NET Framework 4.NET Framework 4 or later on Windows 7 or later, the method attempts to retrieve a CultureInfo object whose identifier is culture from the operating system; if the operating system does not support that culture, the method throws a CultureNotFoundException.

另請參閱

GetCultureInfo(String)

使用指定的文化特性名稱,擷取已快取的唯讀文化特性執行個體。Retrieves a cached, read-only instance of a culture using the specified culture name.

public:
 static System::Globalization::CultureInfo ^ GetCultureInfo(System::String ^ name);
public static System.Globalization.CultureInfo GetCultureInfo (string name);
static member GetCultureInfo : string -> System.Globalization.CultureInfo
Public Shared Function GetCultureInfo (name As String) As CultureInfo

參數

name
String

文化特性的名稱。The name of a culture. name 不區分大小寫。name is not case-sensitive.

傳回

唯讀 CultureInfo 物件。A read-only CultureInfo object.

例外狀況

name 為 null。name is null.

name 指定不支援的文化特性。name specifies a culture that is not supported. 如需詳細資訊,請參閱<呼叫者注意事項>一節。See the Notes to Callers section for more information.

備註

如需 Windows 系統上預先定義的文化特性名稱清單,請參閱windows 支援的語言/區功能變數名稱稱清單中的 [語言標記] 資料行。For a list of predefined culture names on Windows systems, see the Language tag column in the list of language/region names supported by Windows. 文化名稱遵循 BCP 47 定義的標準。Culture names follow the standard defined by BCP 47. 此外,從 Windows 10 開始,name 可以是任何有效的 BCP-47 語言標記。In addition, starting with Windows 10, name can be any valid BCP-47 language tag.

GetCultureInfo 方法會抓取快取的唯讀 CultureInfo 物件。The GetCultureInfo method retrieves a cached, read-only CultureInfo object. 它提供的效能比對應的 CultureInfo.CultureInfo(String) 函式呼叫更好。It offers better performance than a corresponding call to the CultureInfo.CultureInfo(String) constructor.

如果 name 是目前文化特性的名稱,則傳回的 CultureInfo 物件不會反映任何使用者覆寫。If name is the name of the current culture, the returned CultureInfo object does not reflect any user overrides. 這讓方法適用于在系統上沒有實際使用者帳戶的伺服器應用程式或工具,而且需要有效率地載入多個文化特性。This makes the method suitable for server applications or tools that do not have a real user account on the system and that need to load multiple cultures efficiently.

如果 String.Emptyname,則方法會傳回不因文化特性而異。If name is String.Empty, the method returns the invariant culture. 這相當於抓取 InvariantCulture 屬性的值。This is equivalent to retrieving the value of the InvariantCulture property.

給呼叫者的注意事項

如果 name 不是有效的文化特性名稱,.NET Framework 3.5.NET Framework 3.5 和較早的版本會擲回 ArgumentExceptionThe .NET Framework 3.5.NET Framework 3.5 and earlier versions throw an ArgumentException if name is not a valid culture name. .NET Framework 4.NET Framework 4開始,這個方法會擲回 CultureNotFoundExceptionStarting with the .NET Framework 4.NET Framework 4, this method throws a CultureNotFoundException. 從在 Windows 7 或更新版本的 .NET Framework 4.NET Framework 4 或更新版本下執行的應用程式開始,方法會嘗試取出 CultureInfo 物件,其識別碼是從作業系統 name 的,如果作業系統不支援該文化特性,而且如果 name 不是增補或取代文化特性的名稱,此方法就會擲回 CultureNotFoundExceptionStarting with apps that run under the .NET Framework 4.NET Framework 4 or later on Windows 7 or later, the method attempts to retrieve a CultureInfo object whose identifier is name from the operating system; if the operating system does not support that culture, and if name is not the name of a supplementary or replacement culture, the method throws a CultureNotFoundException.

另請參閱

GetCultureInfo(String, String)

擷取文化特性的快取、唯讀執行個體。Retrieves a cached, read-only instance of a culture. 這些參數會指定文化特性,這個文化特性使用另一個文化特性所指定的 TextInfoCompareInfo 物件來初始化。Parameters specify a culture that is initialized with the TextInfo and CompareInfo objects specified by another culture.

public:
 static System::Globalization::CultureInfo ^ GetCultureInfo(System::String ^ name, System::String ^ altName);
public static System.Globalization.CultureInfo GetCultureInfo (string name, string altName);
static member GetCultureInfo : string * string -> System.Globalization.CultureInfo
Public Shared Function GetCultureInfo (name As String, altName As String) As CultureInfo

參數

name
String

文化特性的名稱。The name of a culture. name 不區分大小寫。name is not case-sensitive.

altName
String

文化特性的名稱,這個文化特性提供 TextInfoCompareInfo 物件,而這些物件是用來初始化 nameThe name of a culture that supplies the TextInfo and CompareInfo objects used to initialize name. altName 不區分大小寫。altName is not case-sensitive.

傳回

唯讀 CultureInfo 物件。A read-only CultureInfo object.

例外狀況

namealtName 為 null。name or altName is null.

namealtName 指定不支援的文化特性 (Culture)。name or altName specifies a culture that is not supported. 如需詳細資訊,請參閱<呼叫者注意事項>一節。See the Notes to Callers section for more information.

備註

如需 Windows 系統上預先定義的文化特性名稱清單,請參閱windows 支援的語言/區功能變數名稱稱清單中的 [語言標記] 資料行。For a list of predefined culture names on Windows systems, see the Language tag column in the list of language/region names supported by Windows. 文化名稱遵循 BCP 47 定義的標準。Culture names follow the standard defined by BCP 47. 此外,從 Windows 10 開始,name 可以是任何有效的 BCP-47 語言標記。In addition, starting with Windows 10, name can be any valid BCP-47 language tag.

GetCultureInfo 方法會取得快取的唯讀 CultureInfo 物件。The GetCultureInfo method obtains a cached, read-only CultureInfo object. 它提供的效能比對應的 CultureInfo 函式呼叫更好。It offers better performance than a corresponding call to a CultureInfo constructor. 方法是用來建立類似于 name 參數所指定的文化特性,但具有不同的排序和大小寫規則。The method is used to create a culture similar to that specified by the name parameter, but with different sorting and casing rules.

如果 namealtName 是目前文化特性的名稱,則傳回的物件不會反映任何使用者覆寫。If name or altName is the name of the current culture, the returned objects do not reflect any user overrides. 如果 String.Emptyname,則方法會傳回不因文化特性而異。If name is String.Empty, the method returns the invariant culture. 這相當於抓取 InvariantCulture 屬性的值。This is equivalent to retrieving the value of the InvariantCulture property. 如果 String.EmptyaltName,則方法會使用不因文化特性而異的書寫系統和比較規則。If altName is String.Empty, the method uses the writing system and comparison rules specified by the invariant culture.

給呼叫者的注意事項

如果 namealtName 不是有效的文化特性名稱,.NET Framework 3.5.NET Framework 3.5 和較早的版本就會擲回 ArgumentExceptionThe .NET Framework 3.5.NET Framework 3.5 and earlier versions throw an ArgumentException if name or altName is not a valid culture name. .NET Framework 4.NET Framework 4開始,這個方法會擲回 CultureNotFoundExceptionStarting with the .NET Framework 4.NET Framework 4, this method throws a CultureNotFoundException. 從在 Windows 7 或更新版本的 .NET Framework 4.NET Framework 4 或更新版本下執行的應用程式開始,方法會嘗試取出 CultureInfo 物件,其識別碼是從作業系統 name 的,如果作業系統不支援該文化特性,而且如果 name 不是增補或取代文化特性的名稱,此方法就會擲回 CultureNotFoundException 例外狀況。Starting with apps that run under the .NET Framework 4.NET Framework 4 or later on Windows 7 or later, the method attempts to retrieve a CultureInfo object whose identifier is name from the operating system; if the operating system does not support that culture, and if name is not the name of a supplementary or replacement culture, the method throws a CultureNotFoundException exception. 從在 Windows 7 或更新版本的 .NET Framework 4.NET Framework 4 或更新版本下執行的應用程式開始,方法會嘗試取出 CultureInfo 物件,其識別碼是從作業系統 name 的,如果作業系統不支援該文化特性,而且如果 name 不是增補或取代文化特性的名稱,此方法就會擲回 CultureNotFoundException 例外狀況。Starting with apps that run under the .NET Framework 4.NET Framework 4 or later on Windows 7 or later, the method attempts to retrieve a CultureInfo object whose identifier is name from the operating system; if the operating system does not support that culture, and if name is not the name of a supplementary or replacement culture, the method throws a CultureNotFoundException exception.

另請參閱

適用於