C# HashSet CopyTo(T[])

Description

HashSet CopyTo(T[]) copies the elements of a HashSet object to an array.

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 HashSet object. 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);

    }
}




















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




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack