C# HashSet HashSet()

Description

HashSet HashSet (IEnumerable ) initializes a new instance of the HashSet class that uses the default equality comparer for the set type, contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.

Syntax


public HashSet(
   collection
)

Parameters

  • collection - The collection whose elements are copied to the new set.

Example


//from   w  ww. ja va  2 s  .  co  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 < 5; i++)
    {
        evenNumbers.Add(i * 2);
    }
  }
}




















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




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack