SortedSet<T>.RemoveWhere(Predicate<T>) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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>
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
match
is null
.
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.
// 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}")
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.