System.Collections.ArrayList.CopyTo Method

Copies the entire ArrayList to a compatible one-dimensional Array, starting at the specified index of the target array.

Syntax

public virtual void CopyTo (Array array, int arrayIndex)

Parameters

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

Exceptions

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

array has more than one dimension.

-or-

arrayIndex >= array.Length.

-or-

arrayIndex + ArrayList.Count of the current instance > array.Length.

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

Remarks

The specified array must be of a compatible type.

This method uses erload:System.Array.Copy to copy the elements.

The elements are copied to the Array in the same order in which the enumerator iterates through the ArrayList.

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

Requirements

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