Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

CultureInfo.CurrentCulture Property

Gets or sets the CultureInfo object that represents the culture used by the current thread.

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

public static CultureInfo CurrentCulture { get; set; }

Property Value

Type: System.Globalization.CultureInfo
An object that represents the culture used by the current thread.

ExceptionCondition
ArgumentNullException

The property is set to null.

The CultureInfo object that is returned by this property and its associated objects determine the default format for dates, times, numbers, currency values, the sorting order of text, casing conventions, and string comparisons.

The current culture is a property of the executing thread, which is returned by the static Thread.CurrentThread property. The value of the CultureInfo.CurrentCulture property corresponds to the value of the Thread.CurrentCulture property. Retrieving the value of the CultureInfo.CurrentCulture property is equivalent to retrieving the CultureInfo object returned by the Thread.CurrentThread.CurrentCulture property. Starting with the .NET Framework 4.6 RC, setting the value of the CultureInfo.CurrentCulture property also changes the current thread culture.

NoteNote

In the .NET Framework 4.5.2 and earlier versions, the CurrentCulture property is read-only; that is, you can retrieve the property value, but you cannot set it. To change the current culture, you assign the CultureInfo object that represents the new culture to the Thread.CurrentThread.CurrentCulture property. Starting with the .NET Framework 4.6 RC, the CurrentCulture property is read-write; you can both set and retrieve the property's value. If you do set the property value to a CultureInfo object that represents a new culture, the value of the Thread.CurrentThread.CurrentCulture property also changes.

In this section:

How a Thread's Culture Is Determined
Explicitly Setting the CurrentCulture Property
The Current Culture and User Overrides
Culture and Windows Apps

How a Thread's Culture Is Determined

When a thread is started, its culture is initially determined as follows:

  • By retrieving the culture that is specified by the DefaultThreadCurrentCulture property in the application domain in which the thread is executing, if the property value is not null.

  • By calling the Windows GetUserDefaultLocaleName function.

Note that if you set a specific culture that is different from the system-installed culture or the user's preferred culture, and your application starts multiple threads, the current culture of those threads will be the culture that is returned by the GetUserDefaultLocaleName function, unless you assign a culture to the DefaultThreadCurrentCulture property in the application domain in which the thread is executing.

For more information about how the culture of a thread is determined, see the "Culture and threads" section in the CultureInfo reference page.

Explicitly Setting the CurrentCulture Property

Staring with the .NET Framework 4.6 RC, to change the culture that is used by an existing thread, you set the CultureInfo.CurrentCulture property to the new culture. If you explicitly change a thread's culture in this way, that change persists if the thread crosses application domain boundaries. The following example changes the current thread culture to Dutch (Netherlands). It also shows that, when the current thread crosses application domain boundaries, its current culture remains changed.

using System;
using System.Globalization;
using System.Threading;

public class Info : MarshalByRefObject
{
   public void ShowCurrentCulture()
   {
      Console.WriteLine("Culture of {0} in application domain {1}: {2}",
                        Thread.CurrentThread.Name,
                        AppDomain.CurrentDomain.FriendlyName,
                        CultureInfo.CurrentCulture.Name);
   }
}

public class Example
{
   public static void Main()
   {
      Info inf = new Info();
      // Set the current culture to Dutch (Netherlands).
      Thread.CurrentThread.Name = "MainThread";
      CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("nl-NL");
      inf.ShowCurrentCulture();

      // Create a new application domain.
       AppDomain ad = AppDomain.CreateDomain("Domain2");
       Info inf2 = (Info) ad.CreateInstanceAndUnwrap(typeof(Info).Assembly.FullName, "Info");
       inf2.ShowCurrentCulture();                       
   }
}
// The example displays the following output: 
//       Culture of MainThread in application domain ChangeCulture1.exe: nl-NL 
//       Culture of MainThread in application domain Domain2: nl-NL
NoteNote

Changing the culture by using the CultureInfo.CurrentCulture property requires a SecurityPermission permission with the ControlThread value set. Manipulating threads is dangerous because of the security state associated with threads. Therefore, this permission should be given only to trustworthy code, and then only as necessary. You cannot change thread culture in semi-trusted code.

Starting with the .NET Framework 4, you can explicitly change the current thread culture to either a specific culture (such as French (Canada)) or a neutral culture (such as French). When a CultureInfo object represents a neutral culture, the values of CultureInfo properties such as Calendar, CompareInfo, DateTimeFormat, NumberFormat, and TextInfo reflect the specific culture that is associated with the neutral culture. For example, the dominant culture for the English neutral culture is English (United States); the dominant culture for the German culture is German (Germany). The following example illustrates the difference in formatting when the current culture is set to a specific culture, French (Canada), and a neutral culture, French.

using System;
using System.Globalization;
using System.Threading;

public class Example
{
   public static void Main()
   {
      double value = 1634.92;
      CultureInfo.CurrentCulture = new CultureInfo("fr-CA");
      Console.WriteLine("Current Culture: {0}", 
                        CultureInfo.CurrentCulture.Name);
      Console.WriteLine("{0:C2}\n", value);

      Thread.CurrentThread.CurrentCulture = new CultureInfo("fr");
      Console.WriteLine("Current Culture: {0}", 
                        CultureInfo.CurrentCulture.Name);
      Console.WriteLine("{0:C2}", value);
   }
}
// The example displays the following output: 
//       Current Culture: fr-CA 
//       1 634,92 $ 
//        
//       Current Culture: fr 
//       1 634,92 €

You can also use the CultureInfo.CurrentCulture property along with the HttpRequest.UserLanguages property to set the CurrentCulture property of an ASP.NET application to the user's preferred culture, as the following example illustrates.

CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);

The Current Culture and User Overrides

Windows allows users to override the standard property values of the CultureInfo object and its associated objects by using Regional and Language Options in Control Panel. The CultureInfo object returned by the CurrentCulture property reflects these user overrides in the following cases:

  • If the current thread culture is set implicitly by the Windows GetUserDefaultLocaleName function.

  • If the current thread culture defined by the DefaultThreadCurrentCulture property corresponds to the current Windows system culture.

  • If the current thread culture is set explicitly to a culture returned by the CreateSpecificCulture method, and that culture corresponds to the current Windows system culture.

  • If the current thread culture is set explicitly to a culture instantiated by the CultureInfo(String) constructor, and that culture corresponds to the current Windows system culture.

In some cases, particularly for server applications, setting the current culture to a CultureInfo object that reflects user overrides may be undesirable. Instead, you can set the current thread culture to a CultureInfo object that does not reflect user overrides in the following ways:

The Current Culture and Windows apps

In Windows apps, the CurrentCulture property is read-only. You can set the current culture by using the Windows ResourceContext.Languages property. The following example uses it to change the application's current culture either to English (United States) or, if the current culture is already English (United States), to French (France). The value of the CurrentCulture and CurrentUICulture properties are then displayed to a TextBlock control named block. As the output from the example shows, the current culture changes when the ResourceContext.Languages property changes.

ResourceContext context = ResourceManager.Current.DefaultContext;
var list = new List<String>();
if (CultureInfo.CurrentCulture.Name == "en-US")
   list.Add("fr-FR");
else
   list.Add("en-US");

context.Languages = list;
block.Text += String.Format("\nThe current culture is {0}\n",
                            CultureInfo.CurrentCulture);
block.Text += String.Format("The current culture UI is {0}\n",
                            CultureInfo.CurrentUICulture);
// The example displays output like the following if run on a system
// whose current culture is English (United States):
// The current culture is fr-FR
// The current UI culture is fr-FR   
Dim context As ResourceContext = ResourceManager.Current.DefaultContext
Dim list As New List(Of String)()
If CultureInfo.CurrentCulture.Name = "en-US" Then
   list.Add("fr-FR")
Else
   list.Add("en-US")
End If
context.Languages = list
block.Text += String.Format("{1}The current culture is {0}{1}",
                            CultureInfo.CurrentCulture, vbCrLf)
block.Text += String.Format("The current culture UI is {0}\n",
                            CultureInfo.CurrentUICulture)
' The example displays output Like the following if run on a system
' whose current culture Is English (United States):
'    The current culture Is fr-FR
'    The current UI culture Is fr-FR   

The following code example demonstrates how to change the CurrentCulture and CurrentUICulture of the current thread.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Show:
© 2015 Microsoft