共用方式為


BooleanSwitch.Enabled 屬性

定義

取得或設定值,指出此參數是否已啟用或停用。

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,這會列印錯誤訊息,以及發生錯誤的位置。

public ref class BooleanSwitchTest
{
private:

   /* Create a BooleanSwitch for data.*/
   static BooleanSwitch^ dataSwitch = gcnew BooleanSwitch( "Data","DataAccess module" );

public:
   static void MyMethod( String^ location )
   {
      
      //Insert code here to handle processing.
      if ( dataSwitch->Enabled )
            Console::WriteLine( "Error happened at {0}", location );
   }

};

int main()
{
   
   //Run the method that writes an error message specifying the location of the error.
   BooleanSwitchTest::MyMethod( "in main" );
}
//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的值。

適用於

另請參閱