本文档已存档,并且将不进行维护。

CultureInfo.CurrentCulture 属性

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

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

public static CultureInfo CurrentCulture { 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

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.

*/

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

Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。

.NET Framework

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

.NET Compact Framework

受以下版本支持:2.0、1.0

XNA Framework

受以下版本支持:1.0
显示: