C# HashSet CopyTo(T[], Int32)
Description
HashSet
copies the elements
of a HashSet
Syntax
HashSet.CopyTo(T[], Int32)
has the following syntax.
public void CopyTo(
T[] array,
int arrayIndex
)
Parameters
HashSet.CopyTo(T[], Int32)
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. arrayIndex
- The zero-based index in array at which copying begins.
Example
Copies the elements of a HashSet object to an array, starting at the specified array index.
//from w w w . ja v a2s . c o 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);
}
int[] intArray = new int[5];
evenNumbers.CopyTo(intArray, 0);
}
}