Remove elements from a HashSet with conditions defined by the predicate in CSharp
Description
The following code shows how to remove elements from a HashSet with conditions defined by the predicate.
Example
/* w w w . ja va 2s. c o m*/
using System;
using System.Collections.Generic;
public class MainClass{
public static void Main(String[] argv){
HashSet<int> evenNumbers = new HashSet<int>();
for (int i = 0; i < 20; i++)
{
evenNumbers.Add(i);
}
evenNumbers.RemoveWhere(isEven);
foreach(int i in evenNumbers){
Console.WriteLine(i);
}
}
private static bool isEven(int i)
{
return ((i % 2) == 1);
}
}
The code above generates the following result.