Property Value

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, setting the value of the CultureInfo.CurrentCulture property also changes the current thread culture.

Note

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, 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.

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.

If the thread is a thread pool thread that is executing a task-based asynchronous operation and the app targets the .NET Framework 4.6 or a later version of the .NET Framework, its culture is determined by the culture of the calling thread. The following example changes the current culture to Portuguese (Brazil) and launches six tasks, each of which displays its thread ID, its task ID, and its current culture. Each of the tasks (and the threads) has inherited the culture of the calling thread.

For more information, see the "Culture and task-based asynchronous operations" section in the CultureInfo topic.

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.

The CultureInfo.CurrentCulture property is a per-thread setting; that is, each thread can have its own culture. You get the culture of the current thread by retrieving the value of the CultureInfo.CurrentCulture property, as the following example illustrates.

Staring with the .NET Framework 4.6, 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.

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.

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.

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 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:

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

Imports System.Globalization
Imports System.Threading
PublicModule Example
PublicSub Main()
' Display the name of the current thread culture.
Console.WriteLine("CurrentCulture is {0}.", CultureInfo.CurrentCulture.Name)
' Change the current culture to th-TH.
CultureInfo.CurrentCulture = New CultureInfo("th-TH", False)
Console.WriteLine("CurrentCulture is now {0}.", CultureInfo.CurrentCulture.Name)
' Display the name of the current UI culture.
Console.WriteLine("CurrentUICulture is {0}.", CultureInfo.CurrentUICulture.Name)
' Change the current UI culture to ja-JP.
CultureInfo.CurrentUICulture = New CultureInfo("ja-JP", False)
Console.WriteLine("CurrentUICulture is now {0}.", CultureInfo.CurrentUICulture.Name)
EndSubEndModule' The example displays the following output:' CurrentCulture is en-US.' CurrentCulture is now th-TH.' CurrentUICulture is en-US.' CurrentUICulture is now ja-JP.