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 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. 从在 .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)

使用特定的区域性名称检索某个区域性的缓存的只读实例。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. 从在 .NET Framework 4.NET Framework 4 或更高版本的 Windows 7 或更高版本下运行的应用开始,此方法会尝试检索 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 对象,这些对象用于对 name 进行初始化。The 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 指定不受支持的区域性。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. 从在 .NET Framework 4.NET Framework 4 或更高版本的 Windows 7 或更高版本下运行的应用开始,此方法会尝试检索 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. 从在 .NET Framework 4.NET Framework 4 或更高版本的 Windows 7 或更高版本下运行的应用开始,此方法会尝试检索 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.

另请参阅

适用于