SortedSet<T>.RemoveWhere(Predicate<T>) Metoda

Definicja

Usuwa wszystkie elementy zgodne z warunkami zdefiniowanymi przez określony predykat z elementu 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

Parametry

match
Predicate<T>

Delegat, który definiuje warunki elementów do usunięcia.

Zwraca

Liczba elementów, które zostały usunięte z kolekcji SortedSet<T> .

Wyjątki

match to null.

Przykłady

Poniższy przykład usuwa niepożądane elementy z posortowanego zestawu. Ten przykład kodu jest częścią większego przykładu udostępnionego SortedSet<T> dla klasy .

// 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}")

Uwagi

matchprogram nie może modyfikować .SortedSet<T> Może to spowodować nieoczekiwane wyniki.

Wywoływanie tej metody jest operacją O(n) , gdzie n to Count.

Dotyczy