Export (0) Print
Expand All

SortedSet<T>.RemoveWhere Method

Removes all elements that match the conditions defined by the specified predicate from a SortedSet<T>.

Namespace:  System.Collections.Generic
Assembly:  System (in System.dll)

public int RemoveWhere(
	Predicate<T> match
)

Parameters

match
Type: System.Predicate<T>
The delegate that defines the conditions of the elements to remove.

Return Value

Type: System.Int32
The number of elements that were removed from the SortedSet<T> collection..

ExceptionCondition
ArgumentNullException

match is null.

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.

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());


...


// 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;
    }
}


.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft