Share via


ClientTargetCollection.Clear 方法

定義

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

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

範例

下列程式碼範例會從 ClientTargetCollection 集合中移除所有 ClientTarget 物件。

如需如何取得集合的資訊,請參閱類別概觀中的 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

注意

呼叫 Configuration.Save 相當於修改值時 ConfigurationSaveMode 呼叫 Save

如果您使用 Configuration.Save 方法,則適用下列條件:

  • 如果您傳遞 FullModified 參數值,則會 clear 在目前階層層級的組態檔區段中插入 clientTarget 元素。

  • 如果您傳遞 Minimal 參數值,則會在目前階層層級的組態檔區段中新增 clientTarget 一系列 remove 元素。 這會移除階層中較高層級上父組態檔中定義之專案的所有參考 addMinimal使用列舉值時,集合上的一個額外屬性會影響序列化至組態檔的專案。 屬性為 EmitClear ,且預設為 false 。 適用下列其中一個條件:

    • 當 設定為 trueEmitClearclear 元素會 clientTarget 插入組態檔目前階層層級的 區段。 這會移除階層中較高層級上父組態檔中定義之專案的所有參考 add

    • 當 設定為 falseEmitClear ,如果組態檔存在,則會 clearclientTarget 組態檔的 區段中移除專案。

Clear方法實際上會刪除 add 目前階層層級組態檔區段中定義的 clientTarget 專案。 它也會移除階層中較高層級上父組態檔中定義之專案的所有參考 add

注意

元素 add 不會從 clientTarget 父組態檔的 區段中刪除。

適用於

另請參閱