Export (0) Print
Expand All
1 out of 4 rated this helpful - Rate this topic

CultureInfo.CurrentUICulture Property

Gets the CultureInfo that represents the current culture used by the Resource Manager to look up culture-specific resources at run time.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)
public static CultureInfo CurrentUICulture { get; }

Property Value

Type: System.Globalization.CultureInfo
The CultureInfo that represents the current culture used by the Resource Manager to look up culture-specific resources at run time.

The current UI culture is a per-thread property. That is, each thread has its own current UI culture. The CurrentUICulture property returns the value of the System.Threading.Thread.CurrentThread.CurrentUICulture property. When a thread is started, its UI culture is initially determined by calling the Windows GetUserDefaultUILanguage function. To change the user interface culture used by a thread, set the Thread.CurrentUICulture property to the new culture.

Explicitly Setting the Current UI Culture

Although the CultureInfo.CurrentUICulture property is read-only, you can change its value by explicitly setting the Thread.CurrentUICulture property of the current thread. The current UI culture can be set to either a specific culture (such as "en-US" or "de-DE") or to a neutral culture (such as "en" or "de"). The following example sets the current UI culture to "fr-FR" or French (France).


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

public class Example
{
   public static void Main()
   {
      Console.WriteLine("The current UI culture: {0}", 
                        CultureInfo.CurrentUICulture.Name);

      Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR");
      Console.WriteLine("The current UI culture: {0}", 
                        CultureInfo.CurrentUICulture.Name);
   }
}
// The example displays output like the following:
//       The current UI culture: en-US
//       The current UI culture: fr-FR


In a multithreaded application, you can explicitly set the UI culture of any thread by assigning a CultureInfo object that represents that culture to the thread's Thread.CurrentUICulture property.

Implicitly Setting the Current UI Culture

When a thread, including the main application thread, is first created, by default its current UI culture is set by using the system's default culture. On systems that use the Windows operating system, the common language runtime calls the Windows GetUserDefaultUILanguage function to set the current UI culture. GetUserDefaultUILanguage returns the default UI culture set by the user. If the user has not set a default UI language, it returns the culture originally installed on the system.

Note that if you set a specific UI culture that is different from the system-installed UI culture or the user's preferred UI culture, and your application starts multiple threads, the current UI culture of those threads will be the culture returned by the GetUserDefaultUILanguage function.

Security Considerations

Changing the culture of the current thread requires a SecurityPermission permission with the ControlThread value set.

Caution noteCaution

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.

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


using System;
using System.Globalization;
using System.Security.Permissions;
using System.Threading;

[assembly:SecurityPermission( SecurityAction.RequestMinimum, ControlThread = true )]
public class SamplesCultureInfo  {

   public static void 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 = new 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.CurrentUICulture.Name );

      // Changes the CurrentUICulture of the current thread to ja-JP.
      Thread.CurrentThread.CurrentUICulture = new CultureInfo( "ja-JP", false );
      Console.WriteLine( "CurrentUICulture is now {0}.", CultureInfo.CurrentUICulture.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.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.