CultureInfo Constructors

Definition

Overloads

CultureInfo(Int32)

Initializes a new instance of the CultureInfo class based on the culture specified by the culture identifier.

CultureInfo(String)

Initializes a new instance of the CultureInfo class based on the culture specified by name.

CultureInfo(Int32, Boolean)

Initializes a new instance of the CultureInfo class based on the culture specified by the culture identifier and on the Boolean that specifies whether to use the user-selected culture settings from the system.

CultureInfo(String, Boolean)

Initializes a new instance of the CultureInfo class based on the culture specified by name and on the Boolean that specifies whether to use the user-selected culture settings from the system.

CultureInfo(Int32)

Initializes a new instance of the CultureInfo class based on the culture specified by the culture identifier.

public CultureInfo (int culture);
Parameters
culture
Int32

A predefined CultureInfo identifier, LCID property of an existing CultureInfo object, or Windows-only culture identifier.

Exceptions

culture is less than zero.

culture is not a valid culture identifier. See the Notes to Callers section for more information.

Remarks

Predefined culture identifiers are listed in the National Language Support (NLS) API Reference at the Go Global Developer Center.

In most cases, the culture parameter is mapped to the corresponding National Language Support (NLS) locale identifier. The value of the culture parameter becomes the value of the LCID property of the new CultureInfo.

We recommend that you call the locale name constructor CultureInfo.CultureInfo, because locale names are preferable to LCIDs. For custom locales, a locale name is required.

The user might choose to override some of the values associated with the current culture of Windows through the regional and language options portion of Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture. If the specified culture identifier matches the culture identifier of the current Windows culture, this constructor creates a CultureInfo that uses those overrides, including user settings for the properties of the DateTimeFormatInfo instance returned by the DateTimeFormat property, and the properties of the NumberFormatInfo instance returned by the NumberFormat property. If the user settings are incompatible with the culture associated with the CultureInfo (for example, if the selected calendar is not one of the OptionalCalendars) the results of the methods and the values of the properties are undefined.

If the specified culture identifier does not match the identifier of the current Windows culture, this constructor creates a CultureInfo that uses the default values for the specified culture.

The UseUserOverride property is always set to true.

For example, suppose that Arabic (Saudi Arabia) is the current Windows culture and the user has changed the calendar from Hijri to Gregorian.

For cultures that use the euro, the .NET Framework and Windows XP set the default currency as euro. However, older versions of Windows do not. Therefore, if the user of an older version of Windows has not changed the currency setting through the regional and language options portion of Control Panel, the currency might be incorrect. To use the .NET Framework default setting for the currency, the application should use a CultureInfo constructor overload that accepts a useUserOverride parameter and set it to false.

Note

For backwards compatibility, a culture constructed using a culture parameter of 0x0004 or 0x7c04 will have a Name property of zh-CHS or zh-CHT, respectively. You should instead prefer to construct the culture using the current standard culture names of zh-Hans or zh-Hant, unless you have a reason for using the older names.

Notes to Callers

The [!INCLUDE[net_v35_long](~/includes/net-v35-long-md.md)] and earlier versions throw an ArgumentException if culture is not a valid culture identifier. Starting with the [!INCLUDE[net_v40_long](~/includes/net-v40-long-md.md)], this constructor throws a CultureNotFoundException. Starting with apps that run under the [!INCLUDE[net_v40_long](~/includes/net-v40-long-md.md)] 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 exception.

See Also

CultureInfo(String)

Initializes a new instance of the CultureInfo class based on the culture specified by name.

public CultureInfo (string name);
Parameters
name
String

A predefined CultureInfo name, Name of an existing CultureInfo, or Windows-only culture name. name is not case-sensitive.

Exceptions

name is null.

name is not a valid culture name. For more information, see the Notes to Callers section.

Examples

The following example retrieves the current culture. If it is anything other than the French (France) culture, it calls the CultureInfo(String) constructor to instantiate a CultureInfo object that represents the French (France) culture and makes it the current thread culture. Otherwise, it instantiates a CultureInfo object that represents the French (Luxembourg) culture and makes it the current culture.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CultureInfo current = CultureInfo.CurrentCulture;
      Console.WriteLine("The current culture is {0}", current.Name);
      CultureInfo newCulture;
      if (current.Name.Equals("fr-FR"))
         newCulture = new CultureInfo("fr-LU");
      else   
         newCulture = new CultureInfo("fr-FR");
      
      CultureInfo.CurrentCulture = newCulture;
      Console.WriteLine("The current culture is now {0}", 
                        CultureInfo.CurrentCulture.Name);   
   }
}
// The example displays output like the following:
//     The current culture is en-US
//     The current culture is now fr-FR
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim current As CultureInfo = CultureInfo.CurrentCulture
      Console.WriteLine("The current culture is {0}", current.Name)
      Dim newCulture As CultureInfo
      If current.Name.Equals("fr-FR") Then
         newCulture = New CultureInfo("fr-LU")
      Else   
         newCulture = new CultureInfo("fr-FR")
      End If
      
      CultureInfo.CurrentCulture = newCulture
      Console.WriteLine("The current culture is now {0}", 
                        CultureInfo.CurrentCulture.Name)   
   End Sub
End Module
' The example displays output like the following:
'     The current culture is en-US
'     The current culture is now fr-FR

Remarks

For a list of predefined culture names, see the National Language Support (NLS) API Reference at the Go Global Developer Center. In addition, starting with Windows 10, name can be any valid BCP-47 language tag.

If name is String.Empty, the constructor creates an instance of the invariant culture; this is equivalent to retrieving the value of the InvariantCulture property.

The user might choose to override some of the values associated with the current culture of Windows through the regional and language options portion of Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture. If the culture identifier associated with name matches the culture identifier of the current Windows culture, this constructor creates a CultureInfo object that uses those overrides, including user settings for the properties of the DateTimeFormatInfo instance returned by the DateTimeFormat property, and the properties of the NumberFormatInfo instance returned by the NumberFormat property. If the user settings are incompatible with the culture associated with the CultureInfo, for example, if the selected calendar is not one of the OptionalCalendars, the results of the methods and the values of the properties are undefined.

If the culture identifier associated with name does not match the culture identifier of the current Windows culture, this constructor creates a CultureInfo object that uses the default values for the specified culture.

The UseUserOverride property is always set to true.

For example, suppose that Arabic (Saudi Arabia) is the current culture of Windows and the user changed the calendar from Hijri to Gregorian.

The LCID property of the new CultureInfo is set to the culture identifier associated with the specified name.

For cultures that use the euro, the .NET Framework and Windows XP set the default currency as euro. However, older versions of Windows do not do this. Therefore, if the user of an older version of Windows has not changed the currency setting through the regional and language options portion of Control Panel, the currency might be incorrect. To use the .NET Framework default setting for the currency, the application should use a CultureInfo constructor overload that accepts a useUserOverride parameter and set it to false.

Notes to Callers

The [!INCLUDE[net_v35_long](~/includes/net-v35-long-md.md)] and earlier versions throw an ArgumentException if name is not a valid culture name. Starting with the [!INCLUDE[net_v40_long](~/includes/net-v40-long-md.md)], this constructor throws a CultureNotFoundException. Starting with apps that run under the [!INCLUDE[net_v40_long](~/includes/net-v40-long-md.md)] 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.

See Also

CultureInfo(Int32, Boolean)

Initializes a new instance of the CultureInfo class based on the culture specified by the culture identifier and on the Boolean that specifies whether to use the user-selected culture settings from the system.

public CultureInfo (int culture, bool useUserOverride);
Parameters
culture
Int32

A predefined CultureInfo identifier, LCID property of an existing CultureInfo object, or Windows-only culture identifier.

useUserOverride
Boolean

A Boolean that denotes whether to use the user-selected culture settings (true) or the default culture settings (false).

Exceptions

culture is less than zero.

culture is not a valid culture identifier. See the Notes to Callers section for more information.

Remarks

Predefined culture identifiers are listed in the National Language Support (NLS) API Reference at the Go Global Developer Center.

In most cases, the culture parameter is mapped to the corresponding National Language Support (NLS) locale identifier. The value of the culture parameter becomes the value of the LCID property of the new CultureInfo.

We recommend that you call the locale name constructor CultureInfo.CultureInfo, because locale names are preferable to LCIDs. For custom locales, a locale name is required.

The user might choose to override some of the values associated with the current culture of Windows through the regional and language options portion of Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture.

Applications should typically not disallow user overrides. Note that disallowing overrides does not itself guarantee data stability; see the blog entry Culture data shouldn't be considered stable (except for Invariant).

If the UseUserOverride property is set to true and the specified culture identifier matches the identifier of the current Windows culture, this constructor creates a CultureInfo that uses those overrides, including user settings for the properties of the DateTimeFormatInfo instance returned by the DateTimeFormat property, and the properties of the NumberFormatInfo instance returned by the NumberFormat property. If the user settings are incompatible with the culture associated with the CultureInfo, for example, if the selected calendar is not one of the OptionalCalendars, the results of the methods and the values of the properties are undefined.

Otherwise, this constructor creates a CultureInfo that uses the default values for the specified culture.

The value of the useUserOverride parameter becomes the value of the UseUserOverride property.

For example, suppose that Arabic (Saudi Arabia) is the current culture of Windows and the user has changed the calendar from Hijri to Gregorian.

For cultures that use the euro, the .NET Framework and Windows XP set the default currency as euro. However, older versions of Windows do not. Therefore, if the user of an older version of Windows has not changed the currency setting through the regional and language options portion of Control Panel, the currency might be incorrect. To use the .NET Framework default setting for the currency, the application should set the useUserOverride parameter to false.

Note

For backwards compatibility, a culture constructed using a culture parameter of 0x0004 or 0x7c04 will have a Name property of zh-CHS or zh-CHT, respectively. You should instead prefer to construct the culture using the current standard culture names of zh-Hans or zh-Hant, unless you have a reason for using the older names.

Notes to Callers

The [!INCLUDE[net_v35_long](~/includes/net-v35-long-md.md)] and earlier versions throw an ArgumentException if culture is not a valid culture identifier. Starting with the [!INCLUDE[net_v40_long](~/includes/net-v40-long-md.md)], this constructor throws a CultureNotFoundException. Starting with apps that run under the [!INCLUDE[net_v40_long](~/includes/net-v40-long-md.md)] 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 exception.

See Also

CultureInfo(String, Boolean)

Initializes a new instance of the CultureInfo class based on the culture specified by name and on the Boolean that specifies whether to use the user-selected culture settings from the system.

public CultureInfo (string name, bool useUserOverride);
Parameters
name
String

A predefined CultureInfo name, Name of an existing CultureInfo, or Windows-only culture name. name is not case-sensitive.

useUserOverride
Boolean

A Boolean that denotes whether to use the user-selected culture settings (true) or the default culture settings (false).

Exceptions

name is null.

name is not a valid culture name. See the Notes to Callers section for more information.

Remarks

For a list of predefined culture names, see the National Language Support (NLS) API Reference at the Go Global Developer Center. In addition, starting with Windows 10, name can be any valid BCP-47 language tag.

If name is String.Empty, the constructor creates an instance of the invariant culture; this is equivalent to retrieving the value of the InvariantCulture property.

The user might choose to override some of the values associated with the current Windows culture through the regional and language options portion of Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture.

Applications should typically not disallow user overrides. Note that disallowing overrides does not itself guarantee data stability; see the blog entry Culture data shouldn't be considered stable (except for Invariant).

If the UseUserOverride property is set to true and the culture identifier associated with the specified culture name matches the culture identifier of the current Windows culture, this constructor creates a CultureInfo that uses those overrides, including user settings for the properties of the DateTimeFormatInfo instance returned by the DateTimeFormat property, and the properties of the NumberFormatInfo instance returned by the NumberFormat property. If the user settings are incompatible with the culture associated with the CultureInfo, for example, if the selected calendar is not one of the OptionalCalendars, the results of the methods and the values of the properties are undefined.

Otherwise, this constructor creates a CultureInfo that uses the default values for the specified culture.

The value of the useUserOverride parameter becomes the value of the UseUserOverride property.

For example, suppose that Arabic (Saudi Arabia) is the current culture of Windows and the user changed the calendar from Hijri to Gregorian.

The LCID property of the new CultureInfo is set to the culture identifier associated with the specified name.

For cultures that use the euro, the .NET Framework and Windows XP set the default currency as euro. However, older versions of Windows do not do this. Therefore, if the user of an older version of Windows has not changed the currency setting through the regional and language options portion of Control Panel, the currency might be incorrect. To use the .NET Framework default setting for the currency, the application should set the useUserOverride parameter to false.

Notes to Callers

The [!INCLUDE[net_v35_long](~/includes/net-v35-long-md.md)] and earlier versions throw an ArgumentException if name is not a valid culture name. Starting with the [!INCLUDE[net_v40_long](~/includes/net-v40-long-md.md)], this constructor throws a CultureNotFoundException. Starting with apps that run under the [!INCLUDE[net_v40_long](~/includes/net-v40-long-md.md)] 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.

See Also

Applies to