HashSet<T>.CopyTo Method

Definition

Copies the elements of a HashSet<T> collection to an array.

Overloads

CopyTo(T[])

Copies the elements of a HashSet<T> object to an array.

CopyTo(T[], Int32)

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

CopyTo(T[], Int32, Int32)

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

CopyTo(T[])

Copies the elements of a HashSet<T> object to an array.

public:
 void CopyTo(cli::array <T> ^ array);
public void CopyTo (T[] array);
member this.CopyTo : 'T[] -> unit
Public Sub CopyTo (array As T())

Parameters

array
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.

Exceptions

array is null.

Remarks

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

CopyTo(T[], Int32)

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

public:
 virtual void CopyTo(cli::array <T> ^ array, int arrayIndex);
public void CopyTo (T[] array, int arrayIndex);
abstract member CopyTo : 'T[] * int -> unit
override this.CopyTo : 'T[] * int -> unit
Public Sub CopyTo (array As T(), arrayIndex As Integer)

Parameters

array
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.

arrayIndex
Int32

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

Implements

Exceptions

array is null.

arrayIndex is less than 0.

arrayIndex is greater than the length of the destination array.

Remarks

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

CopyTo(T[], Int32, Int32)

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

public:
 void CopyTo(cli::array <T> ^ array, int arrayIndex, int count);
public void CopyTo (T[] array, int arrayIndex, int count);
member this.CopyTo : 'T[] * int * int -> unit
Public Sub CopyTo (array As T(), arrayIndex As Integer, count As Integer)

Parameters

array
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.

arrayIndex
Int32

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

count
Int32

The number of elements to copy to array.

Exceptions

array is null.

arrayIndex is less than 0.

-or-

count is less than 0.

arrayIndex is greater than the length of the destination array.

-or-

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

Remarks

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

Applies to