Switch Constructors

Definition

Initializes a new instance of the Switch class.

Overloads

Switch(String, String)

Initializes a new instance of the Switch class.

Switch(String, String, String)

Initializes a new instance of the Switch class, specifying the display name, description, and default value for the switch.

Switch(String, String)

Source:
Switch.cs
Source:
Switch.cs
Source:
Switch.cs

Initializes a new instance of the Switch class.

C#
protected Switch(string displayName, string? description);
C#
protected Switch(string displayName, string description);

Parameters

displayName
String

The name of the switch.

description
String

The description for the switch.

Remarks

When you create a new Switch object, the value of the displayName parameter is used to find initial switch settings. The default value is an empty string ("").

Within the XML configuration file of a .NET Framework app, you can add a switch and set its value, remove a switch, or clear all the switches previously set by the application. Dynamic changes to the configuration file are not detected while the application is executing. You must stop and restart an application before changes to the configuration file take effect. The configuration file should be formatted like the following example:

XML
<configuration>  
  <system.diagnostics>  
    <switches>  
      <add name="mySwitch" value="10" />  
      <add name="myNewSwitch" value="20" />  
      <remove name="mySwitch" />  
      <clear/>  
    </switches>  
  </system.diagnostics>  
</configuration>  

Notes to Inheritors

To set the value of the switch, set the SwitchSetting property in the constructor.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Switch(String, String, String)

Source:
Switch.cs
Source:
Switch.cs
Source:
Switch.cs

Initializes a new instance of the Switch class, specifying the display name, description, and default value for the switch.

C#
protected Switch(string displayName, string? description, string defaultSwitchValue);
C#
protected Switch(string displayName, string? description, string? defaultSwitchValue);
C#
protected Switch(string displayName, string description, string defaultSwitchValue);

Parameters

displayName
String

The name of the switch.

description
String

The description of the switch.

defaultSwitchValue
String

The default value for the switch.

Remarks

The displayName parameter is used to set the value of the DisplayName property, and the description parameter is use to set the value of the Description property. The defaultSwitchValue parameter is the value for the switch if the Value property is not set by code or by the configuration file attribute. See the Switch(String, String) overload for additional information.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1