Bewerken

Share via


CultureInfo.GetCultureInfo Method

Definition

Retrieves a cached, read-only instance of a culture.

Overloads

GetCultureInfo(String, Boolean)

Retrieves a cached, read-only instance of a culture.

GetCultureInfo(String, String)

Retrieves a cached, read-only instance of a culture. 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.

GetCultureInfo(String)

Retrieves a cached, read-only instance of a culture using the specified culture name.

GetCultureInfo(String, Boolean)

Source:
CultureInfo.cs
Source:
CultureInfo.cs
Source:
CultureInfo.cs

Retrieves a cached, read-only instance of a culture.

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

Parameters

name
String

The name of a culture. It is not case-sensitive.

predefinedOnly
Boolean

true if requesting to create an instance of a culture that is known by the platform. false if it is ok to retreive a made-up culture even if the platform does not carry data for it.

Returns

A read-only instance of a culture.

Remarks

By default, when trying to create any culture and the underlying platform (Windows NLS or ICU) does not carry specific data for this culture, the platform will try constructing a culture with data from other cultures or some constant values.

Setting predefinedOnly to true will ensure a culture is created only if the platform has real data for that culture.

Applies to

GetCultureInfo(String, String)

Source:
CultureInfo.cs
Source:
CultureInfo.cs
Source:
CultureInfo.cs

Retrieves a cached, read-only instance of a culture. 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

Parameters

name
String

The name of a culture. name is not case-sensitive.

altName
String

The name of a culture that supplies the TextInfo and CompareInfo objects used to initialize name. altName is not case-sensitive.

Returns

A read-only CultureInfo object.

Exceptions

name or altName is null.

name or altName specifies a culture that is not supported. See the Notes to Callers section for more information.

Remarks

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. Culture names follow the standard defined by BCP 47. In addition, starting with Windows 10, name can be any valid BCP-47 language tag.

The GetCultureInfo method obtains a cached, read-only CultureInfo object. It offers better performance than a corresponding call to a CultureInfo constructor. The method is used to create a culture similar to that specified by the name parameter, but with different sorting and casing rules.

If name or altName is the name of the current culture, the returned objects do not reflect any user overrides. If name is String.Empty, the method returns the invariant culture. This is equivalent to retrieving the value of the InvariantCulture property. If altName is String.Empty, the method uses the writing system and comparison rules specified by the invariant culture.

Notes to Callers

.NET Framework 3.5 and earlier versions throw an ArgumentException if name or altName is not a valid culture name. Starting with .NET Framework 4, this method throws a CultureNotFoundException. Starting with apps that run under .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.

On .NET 6 and later versions, a CultureNotFoundException is thrown if the app is running in an environment where globalization-invariant mode is enabled, for example, some Docker containers, and a culture other than the invariant culture is specified.

See also

Applies to

GetCultureInfo(Int32)

Source:
CultureInfo.cs
Source:
CultureInfo.cs
Source:
CultureInfo.cs

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

Parameters

culture
Int32

A locale identifier (LCID).

Returns

A read-only CultureInfo object.

Exceptions

culture is less than zero.

culture specifies a culture that is not supported. See the Notes to Caller section for more information.

Remarks

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.

If culture is the locale identifier of the current culture, the returned CultureInfo object does not reflect any user overrides.

Notes to Callers

.NET Framework 3.5 and earlier versions throw an ArgumentException if culture is not a valid culture identifier. Starting with .NET Framework 4, this method throws a CultureNotFoundException. Starting with apps that run under .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.

On .NET 6 and later versions, a CultureNotFoundException is thrown if the app is running in an environment where globalization-invariant mode is enabled, for example, some Docker containers, and a culture other than the invariant culture is specified.

See also

Applies to

GetCultureInfo(String)

Source:
CultureInfo.cs
Source:
CultureInfo.cs
Source:
CultureInfo.cs

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

Parameters

name
String

The name of a culture. name is not case-sensitive.

Returns

A read-only CultureInfo object.

Exceptions

name is null.

name specifies a culture that is not supported. See the Notes to Callers section for more information.

Remarks

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. Culture names follow the standard defined by BCP 47. In addition, starting with Windows 10, name can be any valid BCP-47 language tag.

The GetCultureInfo method retrieves a cached, read-only CultureInfo object. It offers better performance than a corresponding call to the CultureInfo.CultureInfo(String) constructor.

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.

If name is String.Empty, the method returns the invariant culture. This is equivalent to retrieving the value of the InvariantCulture property.

Notes to Callers

.NET Framework 3.5 and earlier versions throw an ArgumentException if name is not a valid culture name. Starting with .NET Framework 4, this method throws a CultureNotFoundException. Starting with apps that run under .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.

On .NET 6 and later versions, a CultureNotFoundException is thrown if the app is running in an environment where globalization-invariant mode is enabled, for example, some Docker containers, and a culture other than the invariant culture is specified.

See also

Applies to