C# SortedSet RemoveWhere
Description
SortedSet
removes all elements
that match the conditions defined by the specified predicate from a SortedSet
Syntax
SortedSet.RemoveWhere
has the following syntax.
public int RemoveWhere(
Predicate<T> match
)
Parameters
SortedSet.RemoveWhere
has the following parameters.
match
- The delegate that defines the conditions of the elements to remove.
Returns
SortedSet.RemoveWhere
method returns The
number of elements that were removed from the SortedSet collection.
Example
using System;//from w w w . j a v a2 s. c o m
using System.Collections;
using System.Collections.Generic;
using System.IO;
class Program
{
static void Main(string[] args)
{
SortedSet<string> set1 = new SortedSet<string>();
set1.Add("a");
set1.Add("b");
set1.Add("d");
set1.Add("d");
SortedSet<string> set2 = new SortedSet<string>();
set2.Add("a");
set2.Add("b");
set2.Add("c");
set2.Add("d");
set1.RemoveWhere(myFunc);
foreach (string s in set1)
{
Console.WriteLine(s);
}
}
private static bool myFunc(string s)
{
if (s.ToLower().EndsWith("a") ||
s.ToLower().EndsWith("b"))
{
return true;
}
else
{
return false;
}
}
}
The code above generates the following result.