System.Collections.ICollection.CopyTo Method

Copies the elements of the ICollection to an Array, starting at a particular Array index.

Syntax

public void CopyTo (Array array, int index)

Parameters

array
The one-dimensional Array that is the destination of the elements copied from ICollection. The Array must have zero-based indexing.
index
The zero-based index in array at which copying begins.

Exceptions

TypeReason
ArgumentNullException array is null.
ArgumentOutOfRangeException index < 0.
ArgumentException

array has more than one dimension.

-or-

index is greater than or equal to array.Length.

-or-

The sum of index and the ICollection.Count of the current instance is greater than array.Length.

InvalidCastExceptionAt least one element in the current instance is not assignment-compatible with the type of array.

Remarks

Operation
As described above.

Usage
Use this method to copy from a collection to a Array.

Requirements

Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0