BooleanSwitch.Enabled 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定一個值,表示開關是否啟用或停用。
public:
property bool Enabled { bool get(); void set(bool value); };
public bool Enabled { get; set; }
member this.Enabled : bool with get, set
Public Property Enabled As Boolean
屬性值
true如果開關已啟用;否則,。 false 預設值為 false。
例外狀況
來電者沒有正確的權限。
範例
以下程式碼範例建立 並 BooleanSwitch 利用開關判斷是否要列印錯誤訊息。 參數會在類別層級建立。 該 Main 方法將其位置傳送到 MyMethod,該會印出錯誤訊息及錯誤發生的位置。
//Class level declaration.
/* Create a BooleanSwitch for data.*/
static BooleanSwitch dataSwitch = new BooleanSwitch("Data", "DataAccess module");
static public void MyMethod(string location)
{
//Insert code here to handle processing.
if (dataSwitch.Enabled)
Console.WriteLine("Error happened at " + location);
}
public static void Main(string[] args)
{
//Run the method that writes an error message specifying the location of the error.
MyMethod("in Main");
}
'Class level declaration.
' Create a BooleanSwitch for data.
Private Shared dataSwitch As New BooleanSwitch("Data", "DataAccess module")
Public Shared Sub MyMethod(location As String)
'Insert code here to handle processing.
If dataSwitch.Enabled Then
Console.WriteLine(("Error happened at " + location))
End If
End Sub
'Entry point which delegates to C-style main Private Function
Public Overloads Shared Sub Main()
Main(System.Environment.GetCommandLineArgs())
End Sub
Overloads Public Shared Sub Main(args() As String)
'Run the method that writes an error message specifying the location of the error.
MyMethod("in Main")
End Sub
備註
預設情況下,此欄位設為 false (停用)。 要啟用開關,將此欄位指派為 true。 要停用開關,將值指派給 false。 此性質的價值由基類性質 SwitchSetting的值決定。