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

Definition

Removes all elements that match the conditions defined by the specified predicate from 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

Parameters

match
Predicate<T> Predicate<T> Predicate<T> Predicate<T>

The delegate that defines the conditions of the elements to remove.

Returns

The number of elements that were removed from the SortedSet<T> collection.

Exceptions

Examples

The following example removes unwanted elements from a sorted set. This code example is part of a larger example provided for the SortedSet<T> class.

// Remove elements that have non-media extensions.
// See the 'isDoc' method.
Console.WriteLine("Remove docs from the set...");
Console.WriteLine("\tCount before: {0}", mediaFiles1.Count.ToString());
mediaFiles1.RemoveWhere(isDoc);
Console.WriteLine("\tCount after: {0}", mediaFiles1.Count.ToString());
' Remove elements that have non-media extensions. See the 'isDoc' method.
Console.WriteLine("Remove docs from the set...")
Console.WriteLine(vbTab & "Count before: {0}", mediaFiles1.Count.ToString)
mediaFiles1.RemoveWhere(AddressOf isDoc)
Console.WriteLine(vbTab & "Count after: {0}", mediaFiles1.Count.ToString)
// Defines a predicate delegate to use
// for the SortedSet.RemoveWhere method.
private static bool isDoc(string s)
{
    if (s.ToLower().EndsWith(".txt") ||
        s.ToLower().EndsWith(".doc") ||
        s.ToLower().EndsWith(".xls") ||
        s.ToLower().EndsWith(".xlsx") ||
        s.ToLower().EndsWith(".pdf") ||
        s.ToLower().EndsWith(".doc") ||
        s.ToLower().EndsWith(".docx"))
    {
        return true;
    }
    else
    {
        return false;
    }
}
' Defines a predicate deligate to use
' for the SortedSet.RemoveWhere method.
Private Function isDoc(ByVal s As String) As Boolean
    If (s.ToLower.EndsWith(".txt") _
                OrElse (s.ToLower.EndsWith(".doc") _
                OrElse (s.ToLower.EndsWith(".xls") _
                OrElse (s.ToLower.EndsWith(".xlsx") _
                OrElse (s.ToLower.EndsWith(".pdf") _
                OrElse (s.ToLower.EndsWith(".doc") _
                OrElse s.ToLower.EndsWith(".docx"))))))) Then
        Return True
    Else
        Return False
    End If
End Function

Remarks

match must not modify the SortedSet<T>. Doing so can cause unexpected results.

Calling this method is an O(n) operation, where n is Count.

Applies to