Switch 建構函式

定義

初始化 Switch 類別的新執行個體。

多載

Switch(String, String)

初始化 Switch 類別的新執行個體。

Switch(String, String, String)

指定的參數顯示名稱、描述和預設值,初始化 Switch 類別的新執行個體。

Switch(String, String)

來源:
Switch.cs
來源:
Switch.cs
來源:
Switch.cs

初始化 Switch 類別的新執行個體。

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

參數

displayName
String

參數的名稱。

description
String

切換控制的描述。

備註

當您建立新的 Switch 物件時,參數的值 displayName 會用來尋找初始參數設定。 預設值為空字串 ("")。

在 .NET Framework 應用程式的 XML 組態檔中,您可以新增參數並設定其值、移除參數,或清除應用程式先前設定的所有參數。 執行應用程式時,不會偵測組態檔的動態變更。 您必須先停止並重新啟動應用程式,組態檔的變更才會生效。 組態檔的格式應該如下列範例所示:

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

給繼承者的注意事項

若要設定 參數的值,請在建 SwitchSetting 構函式中設定 屬性。

另請參閱

適用於

.NET 9 和其他版本
產品 版本
.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
.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)

來源:
Switch.cs
來源:
Switch.cs
來源:
Switch.cs

指定的參數顯示名稱、描述和預設值,初始化 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);

參數

displayName
String

參數的名稱。

description
String

參數的描述。

defaultSwitchValue
String

參數的預設值。

備註

參數 displayName 是用來設定 屬性的值 DisplayName ,而 description 參數則用來設定 屬性的值 Description 。 如果 Value 屬性不是由程式代碼或組態檔屬性所設定,參數defaultSwitchValue就是 參數的值。 如需詳細資訊, Switch(String, String) 請參閱 多載。

適用於

.NET 9 和其他版本
產品 版本
.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
.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