CultureInfo.CurrentCulture 属性

获取表示当前线程使用的区域性的 CultureInfo

**命名空间:**System.Globalization
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Shared ReadOnly Property CurrentCulture As CultureInfo
用法
Dim value As CultureInfo

value = CultureInfo.CurrentCulture
public static CultureInfo CurrentCulture { get; }
public:
static property CultureInfo^ CurrentCulture {
    CultureInfo^ get ();
}
/** @property */
public static CultureInfo get_CurrentCulture ()
public static function get CurrentCulture () : CultureInfo

属性值

表示当前线程使用的区域性的 CultureInfo

备注

区域性是当前执行线程的属性。此只读属性返回 Thread.CurrentCulture。启动线程时,其区域性最初通过使用 Windows API 中的 GetUserDefaultLCID 来确定。若要更改线程使用的区域性,请将 Thread.CurrentCulture 设置为新的区域性。更改 Thread.CurrentThread 的区域性需要设置了 ControlThread 标志的 SecurityPermission。由于安全性状态与线程相关联,因此对线程进行操作具有危险性。因此,仅在必要时才向可信任的代码授予此权限。不能在不完全受信任的代码中更改线程的区域性。

示例

下面的代码示例阐释了如何更改当前线程的 CurrentCultureCurrentUICulture

Imports System
Imports System.Globalization
Imports System.Security.Permissions
Imports System.Threading

<assembly: SecurityPermission(SecurityAction.RequestMinimum, ControlThread := True)>
Public Class SamplesCultureInfo

   Public Shared Sub 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)

   End Sub 'Main 

End Class 'SamplesCultureInfo


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

*/
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.

*/
import System.* ;
import System.Globalization.* ;
import System.Security.Permissions.* ;
import System.Threading.* ;

/** @assembly SecurityPermission(SecurityAction.RequestMinimum, 
        ControlThread = true)
 */
public class SamplesCultureInfo
{
       public static void main(String[] args)
    {
        // Displays the name of the CurrentCulture of the current thread.
        Console.WriteLine("CurrentCulture is {0}.", 
            CultureInfo.get_CurrentCulture().get_Name());

        // Changes the CurrentCulture of the current thread to th-TH.
        System.Threading.Thread.get_CurrentThread().set_CurrentCulture( 
            new CultureInfo("th-TH", false));
        Console.WriteLine("CurrentCulture is now {0}.", 
            CultureInfo.get_CurrentCulture().get_Name());

        // Displays the name of the CurrentUICulture of the current thread.
        Console.WriteLine("CurrentUICulture is {0}.", 
            CultureInfo.get_CurrentUICulture().get_Name());

        // Changes the CurrentUICulture of the current thread to ja-JP.
        System.Threading.Thread.get_CurrentThread().set_CurrentUICulture( 
            new CultureInfo("ja-JP", false));
        Console.WriteLine("CurrentUICulture is now {0}.", 
            CultureInfo.get_CurrentUICulture().get_Name());
    } //main 
} //SamplesCultureInfo

/*
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.
*/

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

CultureInfo 类
CultureInfo 成员
System.Globalization 命名空间
ResourceManager
Thread.CurrentCulture
CurrentUICulture
InstalledUICulture
InvariantCulture
Parent
SecurityPermission
SecurityPermissionAttribute