Thread.CurrentCulture Thread.CurrentCulture Thread.CurrentCulture Thread.CurrentCulture Property

定義

取得或設定目前執行緒的文化特性 (Culture)。Gets or sets the culture for the current thread.

public:
 property System::Globalization::CultureInfo ^ CurrentCulture { System::Globalization::CultureInfo ^ get(); void set(System::Globalization::CultureInfo ^ value); };
public System.Globalization.CultureInfo CurrentCulture { get; set; }
member this.CurrentCulture : System.Globalization.CultureInfo with get, set
Public Property CurrentCulture As CultureInfo

屬性值

表示目前執行緒之文化特性的物件。An object that represents the culture for the current thread.

例外狀況

該屬性設定為 nullThe property is set to null.

僅限 .NET Core:不支援從另一個執行緒讀取或寫入執行緒的文化特性。.NET Core only: Reading or writing the culture of a thread from another thread is not supported.

範例

下列範例示範可讓要顯示在 [控制台] 中設定的文化特性中的 Windows Forms 應用程式的使用者介面執行緒陳述式。The following example shows the threading statement that allows the user interface of a Windows Forms application to display in the culture that is set in Control Panel. 需要額外的程式碼。Additional code is needed.

#using <system.dll>
#using <System.Drawing.dll>
#using <system.windows.forms.dll>

using namespace System;
using namespace System::Threading;
using namespace System::Windows::Forms;
ref class UICulture: public 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.
   }
};


int main()
{
   Application::Run( gcnew UICulture );
}
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());
    }
}
Imports System.Threading
Imports System.Windows.Forms

Public Class UICulture : Inherits Form
    Sub New()

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

    Shared Sub Main()
        Application.Run(New UICulture())
    End Sub
End Class

備註

CultureInfo搭配其相關聯的物件,這個屬性所傳回的物件判斷預設格式的日期、 時間、 數字、 貨幣值,排序順序的文字、 大小寫慣例,以及字串比較。The 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. 請參閱CultureInfo類別若要了解文化特性名稱和識別碼,而異、 中性和特定文化特性之間的差異,並方式文化特性資訊影響執行緒和應用程式定義域。See the 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. 請參閱CultureInfo.CurrentCulture屬性,以了解如何決定執行緒的預設文化特性,以及使用者設定其電腦的文化特性資訊的方式。See the CultureInfo.CurrentCulture property to learn how a thread's default culture is determined, and how users set culture information for their computers.

重要

CurrentCulture屬性無法可靠地運作,搭配目前的執行緒以外的任何執行緒時。The CurrentCulture property doesn't work reliably when used with any thread other than the current thread. 在.NET Framework 中,讀取內容的可靠性,不過將它設定為目前的執行緒以外的執行緒並不是。In .NET Framework, reading the property is reliable, although setting it for a thread other than the current thread is not. 在.NET CoreInvalidOperationException就會擲回,如果執行緒嘗試讀取或寫入CurrentCulture不同的執行緒上的屬性。On .NET Core, an InvalidOperationException is thrown if a thread attempts to read or write the CurrentCulture property on a different thread. 我們建議您改用CultureInfo.CurrentCulture擷取或設定目前的文化特性屬性。We recommend that you use the CultureInfo.CurrentCulture property to retrieve and set the current culture.

開頭.NET Framework 4.NET Framework 4,您可以設定CurrentCulture中性文化特性的屬性。Beginning with the .NET Framework 4.NET Framework 4, you can set the CurrentCulture property to a neutral culture. 這是因為行為CultureInfo類別已變更:當它代表中性文化特性,其屬性值 (特別是, CalendarCompareInfoDateTimeFormatNumberFormat,和TextInfo屬性) 現可看出中性文化特性相關聯的特定文化特性。This is because the behavior of the CultureInfo class has changed: When it represents a neutral culture, its property values (in particular, the Calendar, CompareInfo, DateTimeFormat, NumberFormat, and TextInfo properties) now reflect the specific culture that is associated with the neutral culture. 在舊版的.NET Framework 中,CurrentCulture屬性會擲回NotSupportedException中性文化特性已指派時發生的例外狀況。In earlier versions of the .NET Framework, the CurrentCulture property threw a NotSupportedException exception when a neutral culture was assigned.

安全性

SecurityPermission
用來設定屬性。for setting the property. 相關聯的列舉型別: ControlThreadAssociated enumeration: ControlThread

適用於