C# HashSet HashSet(IEnumerable)
Description
HashSet
initializes
a new instance of the HashSet
Syntax
public HashSet(
IEnumerable<T> collection
)
Parameters
collection
- The collection whose elements are copied to the new set.
Example
The following example shows how to create a HashSet collection from an existing set.
/*from www . j a v a 2s. com*/
using System;
using System.Collections.Generic;
public class MainClass{
public static void Main(String[] argv){
HashSet<int> evenNumbers = new HashSet<int>();
HashSet<int> oddNumbers = new HashSet<int>();
for (int i = 0; i < 5; i++)
{
evenNumbers.Add(i * 2);
oddNumbers.Add((i * 2) + 1);
}
HashSet<int> numbers = new HashSet<int>(evenNumbers);
}
}