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.
2 out of 4 rated this helpful - Rate this topic

CultureInfo.CurrentCulture Property

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

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)
static member CurrentCulture : CultureInfo with get

Property Value

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

The culture is a property of the executing thread. This read-only property is equivalent to retrieving the CultureInfo object returned by the Thread.CurrentCulture property. 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.

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 a null reference (Nothing in Visual Basic).

  • 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

To change the culture that is used by an existing thread, you set the Thread.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.

No code example is currently available or this language may not be supported.
NoteNote

Changing the culture by using the Thread.CurrentThread 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 thread is set to a specific culture, French (Canada), and a neutral culture, French.

No code example is currently available or this language may not be supported.

You can also use the Thread.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.

No code example is currently available or this language may not be supported.

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 following code example demonstrates how to change the CurrentCulture and CurrentUICulture of the current thread.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.