CultureInfo Constructor (String)
Collapse the table of content
Expand the table of content

CultureInfo Constructor (String)

 

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

Namespace:   System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

public CultureInfo(
	string name
)

Parameters

name
Type: System.String

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

Exception Condition
ArgumentNullException

name is null.

CultureNotFoundException

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

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

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

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft