SortedSet<T>.ExceptWith(IEnumerable<T>) 方法

定義

從目前的 SortedSet<T> 物件中,移除指定之集合內的所有項目。

public:
 virtual void ExceptWith(System::Collections::Generic::IEnumerable<T> ^ other);
public void ExceptWith (System.Collections.Generic.IEnumerable<T> other);
abstract member ExceptWith : seq<'T> -> unit
override this.ExceptWith : seq<'T> -> unit
Public Sub ExceptWith (other As IEnumerable(Of T))

參數

other
IEnumerable<T>

要從 SortedSet<T> 物件中移除的項目集合。

實作

例外狀況

othernull

範例

下列範例會從另一個已排序集合中複製的已排序集合中移除專案。 此程式代碼範例是針對 類別提供的較大範例的 SortedSet<T> 一部分。

// Remove elements in mediaFiles1 that are also in mediaFiles2.
Console.WriteLine("Remove duplicates (of mediaFiles2) from the set...");
Console.WriteLine($"\tCount before: {mediaFiles1.Count}");
mediaFiles1.ExceptWith(mediaFiles2);
Console.WriteLine($"\tCount after: {mediaFiles1.Count}");
' Remove elements in mediaFiles1 that are also in mediaFiles2.
Console.WriteLine("Remove duplicates (of mediaFiles2) from the set...")
Console.WriteLine($"{vbTab}Count before: {mediaFiles1.Count}")
mediaFiles1.ExceptWith(mediaFiles2)
Console.WriteLine($"{vbTab}Count after: {mediaFiles1.Count}")

備註

這個方法會移除目前 SortedSet<T> 中也位於 other中的任何專案。 中的 other 重複值會被忽略。

這個方法是 O(n) 作業,其中 n 是參數中的 other 元素數目。

適用於