Remove the specified element from a HashSet in CSharp
Description
The following code shows how to remove the specified element from a HashSet.
Example
using System;/*from w w w . j a v a 2s . co m*/
using System.Collections.Generic;
public class MainClass
{
public static void Main(String[] argv)
{
HashSet<int> evenNumbers = new HashSet<int>();
for (int i = 0; i < 5; i++)
{
evenNumbers.Add(i * 2);
}
foreach(int s in evenNumbers){
Console.WriteLine(s);
}
if (evenNumbers.Contains(0))
{
evenNumbers.Remove(0);
}
foreach(int s in evenNumbers){
Console.WriteLine(s);
}
}
}
The code above generates the following result.