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 the CultureInfo that represents the culture used by the current thread.

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

public:
static property CultureInfo^ CurrentCulture {
	CultureInfo^ get ();
}

Property Value

Type: System.Globalization::CultureInfo
The CultureInfo 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. When a thread is started, its culture is initially determined by calling the Windows GetUserDefaultLocaleName function. To change the culture that is used by an existing thread, you set the Thread::CurrentCulture property to the new culture. 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.

NoteNote

The CurrentCulture property is used for formatting and other globalization tasks. In contrast, the CurrentUICulture property can be set to neutral cultures that may not have formatting information.

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 returned by the GetUserDefaultLocaleName function.

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


using namespace System;
using namespace System::Globalization;
using namespace System::Security::Permissions;
using namespace System::Threading;

[assembly:SecurityPermission(SecurityAction::RequestMinimum,ControlThread=true)];
int main()
{

   // Displays the name of the CurrentCulture of the current thread.
   Console::WriteLine(  "CurrentCulture is {0}.", CultureInfo::CurrentCulture->Name );

   // Changes the CurrentCulture of the current thread to th-TH.
   Thread::CurrentThread->CurrentCulture = gcnew CultureInfo(  "th-TH",false );
   Console::WriteLine(  "CurrentCulture is now {0}.", CultureInfo::CurrentCulture->Name );

   // Displays the name of the CurrentUICulture of the current thread.
   Console::WriteLine(  "CurrentUICulture is {0}.", CultureInfo::CurrentCulture->Name );

   // Changes the CurrentUICulture of the current thread to ja-JP.
   Thread::CurrentThread->CurrentUICulture = gcnew CultureInfo(  "ja-JP",false );
   Console::WriteLine(  "CurrentUICulture is now {0}.", CultureInfo::CurrentCulture->Name );
}

/*
This code produces the following output, if the ControlThread permission is granted (for example, if this code is run from the local drive).

CurrentCulture is en-US.
CurrentCulture is now th-TH.
CurrentUICulture is en-US.
CurrentUICulture is now ja-JP.

*/


.NET Framework

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

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

Show:
© 2014 Microsoft