C# HashSet Clear

Description

HashSet Clear removes all elements from a HashSet object.

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();
  }
}




















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack