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

定義

從目前的 SortedSet<T> 物件中,移除指定之集合內的所有項目。Removes all elements that are in a specified collection from the current SortedSet<T> object.

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> 物件中移除的項目集合。The collection of items to remove from the SortedSet<T> object.

實作

例外狀況

othernullother is null.

範例

下列範例會從已排序的集合中移除已在另一個已排序集合中重複的專案。The following example removes elements from a sorted set that are duplicated in another sorted set. 這個程式碼範例是針對類別提供之較大範例的一部分 SortedSet<T>This code example is part of a larger example provided for the SortedSet<T> class.

// 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> 也在中的任何元素 otherThis method removes any element in the current SortedSet<T> that is also in other. 中的重複值 other 會被忽略。Duplicate values in other are ignored.

這個方法是一 O(n) 項作業,其中 n 是參數中的元素數目 otherThis method is an O(n) operation, where n is the number of elements in the other parameter.

適用於