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

定义

从 a 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> 集合中删除的元素数。

例外

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

适用于