BooleanSwitch.Enabled Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets or sets a value indicating whether the switch is enabled or disabled.

Namespace:   System.Diagnostics
Assembly:  System (in System.dll)

member Enabled : bool with get, set

Property Value

Type: System.Boolean

true if the switch is enabled; otherwise, false. The default is false.

Exception Condition

The caller does not have the correct permission.

By default, this field is set to false (disabled). To enable the switch, assign this field the value of true. To disable the switch, assign the value to false. The value of this property is determined by the value of the base class property SwitchSetting.


This method uses the SecurityAction.LinkDemand flag to prevent being called from untrusted code; only the immediate caller is required to have SecurityPermissionAttribute.UnmanagedCode permission. If your code can be called from partially trusted code, do not pass the user input to Marshal class methods without validation.

The following code example creates a BooleanSwitch and uses the switch to determine whether to print an error message. The switch is created at the class level. The Main method passes its location to MyMethod, which prints an error message and the location where the error occurred.

No code example is currently available or this language may not be supported.


for operating with unmanaged code. Demand value LinkDemand; Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

.NET Framework
Available since 1.1
Return to top