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>

用于定义要移除的元素应满足的条件的委托。

返回

Int32

SortedSet<T> 集合中移除的元素数。

例外

matchnull

示例

以下示例从排序集中删除不需要的元素。 此代码示例是为类提供的大型示例的 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)操作,其中 nCount

适用于