語言

SortedSet<T>.RemoveWhere(Predicate<T>) 方法

定義

從 中 SortedSet<T>移除所有符合指定謂詞定義條件的元素。

public:
 int RemoveWhere(Predicate<T> ^ match);
public int RemoveWhere(Predicate<T> match);
member this.RemoveWhere : Predicate<'T> -> int
Public Function RemoveWhere (match As Predicate(Of T)) As Integer

參數

match
Predicate<T>

代表定義要移除元素的條件。

傳回

從收藏中移除 SortedSet<T> 的元素數量。

例外狀況

match 是 null。

範例

以下範例是從排序集合中移除不需要的元素。 此程式碼範例是本類別更大範例 SortedSet<T> 的一部分。

// Defines a predicate delegate to use
// for the SortedSet.RemoveWhere method.
private static bool IsDoc(string s)
{
    s = s.ToLower();
    return (s.EndsWith(".txt") ||
        s.EndsWith(".xls") ||
        s.EndsWith(".xlsx") ||
        s.EndsWith(".pdf") ||
        s.EndsWith(".doc") ||
        s.EndsWith(".docx"));
}
' Defines a predicate delegate to use
' for the SortedSet.RemoveWhere method.
Private Function IsDoc(s As String) As Boolean
    s = s.ToLower()
    Return s.EndsWith(".txt") OrElse 
            s.EndsWith(".doc") OrElse 
            s.EndsWith(".xls") OrElse
            s.EndsWith(".xlsx") OrElse
            s.EndsWith(".pdf") OrElse
            s.EndsWith(".doc") OrElse
            s.EndsWith(".docx")
End Function
// Remove elements that have non-media extensions.
// See the 'IsDoc' method.
Console.WriteLine("Remove docs from the set...");
Console.WriteLine($"\tCount before: {mediaFiles1.Count}");
mediaFiles1.RemoveWhere(IsDoc);
Console.WriteLine($"\tCount after: {mediaFiles1.Count}");
' Remove elements that have non-media extensions. See the 'IsDoc' method.
Console.WriteLine("Remove docs from the set...")
Console.WriteLine($"{vbTab}Count before: {mediaFiles1.Count}")
mediaFiles1.RemoveWhere(AddressOf IsDoc)
Console.WriteLine($"{vbTab}Count after: {mediaFiles1.Count}")

備註

match 不得修改 SortedSet<T>。 這樣做可能會帶來意想不到的結果。

呼叫此方法是一個 O(n) 操作,其中 n 為 Count。

適用於