C# HashSet CopyTo(T[], Int32, Int32)
Description
HashSet
copies the
specified number of elements of a HashSet
Syntax
HashSet.CopyTo(T[], Int32, Int32)
has the following syntax.
public void CopyTo(
T[] array,//from www . j av a 2 s . c om
int arrayIndex,
int count
)
Parameters
HashSet.CopyTo(T[], Int32, 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.count
- The number of elements to copy to array.
Example
Copies the specified number of elements of a HashSet object to an array, starting at the specified array index.
using System;/*from w w w . j ava 2s .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, 0, 2);
}
}