Export (0) Print
Expand All

BooleanSwitch Constructor (String, String)

Initializes a new instance of the BooleanSwitch class with the specified display name and description.

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

Public Sub New ( _
	displayName As String, _
	description As String _


Type: System.String

The name to display on a user interface.

Type: System.String

The description of the switch.

When you create a BooleanSwitch, the displayName parameter is used to find initial switch settings. If the constructor cannot find initial settings, the Enabled property is set to false (disabled).

To set the level of your BooleanSwitch, edit the configuration file corresponding to the name of your application. Within this file, you can add a switch and set its value, remove a switch, or clear all switches previously set by the application. The configuration file should be formatted like the following example:

           <add name="mySwitch" value="10" />
           <add name="myNewSwitch" value="20" />
           <remove name="mySwitch" />

The switches you created should be static.

The following 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 where the error occurred.

' 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 'MyMethod

' Entry point which delegates to C-style main function. 
Public Overloads Shared Sub Main()
End Sub 

Overloads Public Shared Sub Main(args() As String)
    ' Run the method which writes an error message specifying the location of the error.
    MyMethod("in Main")
End Sub 'Main

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft