ClientTargetCollection.Clear 方法

定義

移除集合中的所有 ClientTarget 物件。

public:
 void Clear();
public void Clear();
member this.Clear : unit -> unit
Public Sub Clear ()

範例

以下程式碼範例將移除集合中ClientTarget的所有ClientTargetCollection物件。

關於如何取得集合的資訊,請參閱課程總覽中的 ClientTargetCollection 程式碼範例。


           // Clear the client target collection.
           clientTargets.Clear();

           // Update the configuration file.
           if (!clientTargetSection.IsReadOnly())
             configuration.Save();
' Clear the client target collection.
clientTargets.Clear()

' Update the configuration file.
If Not clientTargetSection.IsReadOnly() Then
    configuration.Save()
End If

備註

呼叫該Clear方法後更新設定檔的結果取決於所選值。ConfigurationSaveMode 要更新設定檔,請使用以下兩種方法之一: Configuration.SaveConfiguration.Save

Note

呼叫 Configuration.SaveSave 同於當值被修改時 ConfigurationSaveMode 呼叫。

若使用此 Configuration.Save 方法,需遵守以下條件:

  • 如果你傳遞 Full or Modified 參數值,那麼在當前階層層級的設定檔區段會插入clear一個clientTarget元素。

  • 如果你傳遞參數值,Minimalremove會在目前階層層級的設定檔區塊中加入clientTarget一系列元素。 此舉移除階層結構中父組態檔案中定義元素的所有參考 add 。 列 Minimal 舉值時,集合上的一個額外屬性會影響序列化到設定檔的內容。 屬性是 和 EmitClear 預設 false 為 。 以下其中一個條件適用:

    • EmitClear 設定為 true時, clear 會在當前階層層級的配置檔區段插入 clientTarget 一個元素。 此舉移除階層結構中父組態檔案中定義元素的所有參考 add

    • EmitClear 設為 false時,該 clear 元素會從目前階層層級的配置檔案區段中移除 clientTarget (若存在)。

Clear 方法實際上會 add 刪除設定檔中當前階層層級中定義 clientTarget 的元素。 它也會移除階層 add 結構中父組態檔案中定義元素的所有參考。

Note

add這些元素不會從clientTarget父組態檔案的區塊中刪除。

適用於

另請參閱