HashSet<T>.CopyTo Method (T[], Int32, Int32)

Copies the specified number of elements of a HashSet<T> object to an array, starting at the specified array index.

Namespace:  System.Collections.Generic
Assemblies:   System.Core (in System.Core.dll)
  System.Collections (in System.Collections.dll)

public void CopyTo(
	T[] array,
	int arrayIndex,
	int count


Type: T[]

The one-dimensional array that is the destination of the elements copied from the HashSet<T> object. The array must have zero-based indexing.

Type: System.Int32

The zero-based index in array at which copying begins.

Type: System.Int32

The number of elements to copy to array.


array is null.


arrayIndex is less than 0.


count is less than 0.


arrayIndex is greater than the length of the destination array.


count is greater than the available space from the index to the end of the destination array.

This method is an O(n) operation, where n is count.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft