C# HashSet CopyTo(T[])
Description
HashSet
copies the elements of a
HashSet
Syntax
HashSet.CopyTo(T[])
has the following syntax.
public void CopyTo(
T[] array
)
Parameters
HashSet.CopyTo(T[])
has the following parameters.
array
- The one-dimensional array that is the destination of the elements copied from the HashSetobject. The array must have zero-based indexing.
Example
Copies the elements of a HashSet object to an array.
using System;//www. ja va 2 s . c o 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);
}
int[] intArray = new int[5];
evenNumbers.CopyTo(intArray);
}
}