CultureInfo.GetCultureInfo CultureInfo.GetCultureInfo CultureInfo.GetCultureInfo CultureInfo.GetCultureInfo Method

定義

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

多載

GetCultureInfo(Int32) GetCultureInfo(Int32) GetCultureInfo(Int32) GetCultureInfo(Int32)

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

GetCultureInfo(String) GetCultureInfo(String) GetCultureInfo(String) GetCultureInfo(String)

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

GetCultureInfo(String, String) GetCultureInfo(String, String) GetCultureInfo(String, String) 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) GetCultureInfo(Int32) GetCultureInfo(Int32) 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 Int32 Int32 Int32

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

傳回

例外狀況

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.

給呼叫者的注意事項

ArgumentException .NET Framework 3.5.NET Framework 3.5 如果culture不是有效的文化特性識別碼,和較早的版本會擲回。The .NET Framework 3.5.NET Framework 3.5 and earlier versions throw an ArgumentException if culture is not a valid culture identifier. 從開始CultureNotFoundException,這個方法會擲回。 .NET Framework 4.NET Framework 4Starting with the .NET Framework 4.NET Framework 4, this method throws a CultureNotFoundException. 從在.NET Framework 4.NET Framework 4或更新版本的 Windows 7 或更新版本上執行的應用程式開始,方法會嘗試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) GetCultureInfo(String) GetCultureInfo(String) 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 String String String

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

傳回

例外狀況

name 指定不支援的文化特性 (Culture)。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.

方法會抓取快取的唯讀CultureInfo物件。 GetCultureInfoThe 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.

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

給呼叫者的注意事項

ArgumentException .NET Framework 3.5.NET Framework 3.5 如果name不是有效的文化特性名稱,和較早的版本會擲回。The .NET Framework 3.5.NET Framework 3.5 and earlier versions throw an ArgumentException if name is not a valid culture name. 從開始CultureNotFoundException,這個方法會擲回。 .NET Framework 4.NET Framework 4Starting with the .NET Framework 4.NET Framework 4, this method throws a CultureNotFoundException. 從在.NET Framework 4.NET Framework 4或更新版本的 Windows 7 或更新版本上執行的應用程式開始,方法會嘗試CultureInfo抓取識別碼name來自作業系統的物件; 如果作業系統不支援該文化特性,則為,如果不是補充或取代文化特性的名稱,方法CultureNotFoundException會擲回。 nameStarting 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) GetCultureInfo(String, String) GetCultureInfo(String, String) 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 String String String

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

altName
String String String String

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

傳回

例外狀況

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.

方法會取得快取的唯讀CultureInfo物件。 GetCultureInfoThe 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. 如果nameString.Empty,則方法會傳回不因文化特性而異。If name is String.Empty, the method returns the invariant culture. 這相當於抓取InvariantCulture屬性的值。This is equivalent to retrieving the value of the InvariantCulture property. 如果altNameString.Empty,則方法會使用不因文化特性而異的書寫系統和比較規則。If altName is String.Empty, the method uses the writing system and comparison rules specified by the invariant culture.

給呼叫者的注意事項

ArgumentException如果 .NET Framework 3.5.NET Framework 3.5name不是有效的文化特性名稱,和較早的版本會擲回。 altNameThe .NET Framework 3.5.NET Framework 3.5 and earlier versions throw an ArgumentException if name or altName is not a valid culture name. 從開始CultureNotFoundException,這個方法會擲回。 .NET Framework 4.NET Framework 4Starting with the .NET Framework 4.NET Framework 4, this method throws a CultureNotFoundException. 從在.NET Framework 4.NET Framework 4或更新版本的 Windows 7 或更新版本上執行的應用程式開始,方法會嘗試CultureInfo抓取識別碼name來自作業系統的物件; 如果作業系統不支援該文化特性,則為,如果不是補充或取代文化特性的名稱,方法CultureNotFoundException會擲回例外狀況。 nameStarting 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. 從在.NET Framework 4.NET Framework 4或更新版本的 Windows 7 或更新版本上執行的應用程式開始,方法會嘗試CultureInfo抓取識別碼name來自作業系統的物件; 如果作業系統不支援該文化特性,則為,如果不是補充或取代文化特性的名稱,方法CultureNotFoundException會擲回例外狀況。 nameStarting 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.

另請參閱

適用於