SortedSet<T>.RemoveWhere(Predicate<T>) Método

Definición

Quita de SortedSet<T> todos los elementos que cumplen las condiciones definidas por el predicado especificado.

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

Parámetros

match
Predicate<T>

Delegado que define las condiciones de los elementos que se van a quitar.

Devoluciones

Int32

Número de elementos que se quitaron de la colección SortedSet<T>.

Excepciones

match es null.

Ejemplos

En el ejemplo siguiente se quitan elementos no deseados de un conjunto ordenado. Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la SortedSet<T> clase .

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

Comentarios

matchno debe modificar .SortedSet<T> Si lo hace, puede provocar resultados inesperados.

Llamar a este método es una O(n) operación, donde n es Count.

Se aplica a