本文由机器翻译。若要查看英语原文,请勾选“英语”复选框。 也可将鼠标指针移到文本上,在弹出窗口中显示英语原文。
翻译
英语

Thread.CurrentCulture 属性

 

获取或设置当前线程的区域性。

命名空间:   System.Threading
程序集:  mscorlib(位于 mscorlib.dll)

public CultureInfo CurrentCulture {
	get;
	[SecurityPermissionAttribute(SecurityAction.Demand, ControlThread = true)]
	set;
}

属性值

Type: System.Globalization.CultureInfo

表示当前线程的区域性的对象。

Exception Condition
ArgumentNullException

属性设置为 null

The T:System.Globalization.CultureInfo object that is returned by this property, together with its associated objects, determine the default format for dates, times, numbers, currency values, the sorting order of text, casing conventions, and string comparisons. See the T:System.Globalization.CultureInfo class to learn about culture names and identifiers, the differences between invariant, neutral, and specific cultures, and the way culture information affects threads and application domains. See the P:System.Globalization.CultureInfo.CurrentCulture property to learn how a thread's default culture is determined, and how users set culture information for their computers.

Beginning with the net_v40_long, you can set the P:System.Threading.Thread.CurrentCulture property to a neutral culture. This is because the behavior of the T:System.Globalization.CultureInfo class has changed: When it represents a neutral culture, its property values (in particular, the P:System.Globalization.CultureInfo.Calendar, P:System.Globalization.CultureInfo.CompareInfo, P:System.Globalization.CultureInfo.DateTimeFormat, P:System.Globalization.CultureInfo.NumberFormat, and P:System.Globalization.CultureInfo.TextInfo properties) now reflect the specific culture that is associated with the neutral culture. In earlier versions of the .NET Framework, the P:System.Threading.Thread.CurrentCulture property threw a T:System.NotSupportedException exception when a neutral culture was assigned.

The following code example shows the threading statement that allows the user interface of a Windows Forms to display in the culture that is set in Control Panel. Additional code is needed.

using System;
using System.Threading;
using System.Windows.Forms;

class UICulture : Form
{
    public UICulture()
    {
        // Set the user interface to display in the
        // same culture as that set in Control Panel.
        Thread.CurrentThread.CurrentUICulture = 
            Thread.CurrentThread.CurrentCulture;

        // Add additional code.
    }

    static void Main()
    {
        Application.Run(new UICulture());
    }
}

SecurityPermission

for setting the property. Associated enumeration: F:System.Security.Permissions.SecurityPermissionFlag.ControlThread

.NET Framework
自 1.1 起可用
可移植类库
可移植 .NET 平台 中受支持
Silverlight
自 2.0 起可用
Windows Phone Silverlight
自 7.0 起可用
返回页首
显示: