SortedSet<T>.ExceptWith(IEnumerable<T>) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從當前 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> 的物品集合。
實作
例外狀況
other 是 null。
範例
以下範例是從一個已排序集合中移除在另一個排序集合中重複的元素。 此程式碼範例是本類別更大範例 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 log m) 運算,其中 m 是 Count ,是 n 中的 other元素數。