C# HashSet Clear
Description
HashSet
removes all elements from a HashSet
Syntax
HashSet.Clear
has the following syntax.
public void Clear()
Example
Removes all elements from a HashSet object.
using System;/* w w w. j a va 2s.c om*/
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);
}
evenNumbers.Clear();
}
}