.NET Framework Class Library
Collection<(Of <(T>)>)..::.CopyTo Method

Updated: November 2007

Copies the entire Collection<(Of <(T>)>) to a compatible one-dimensional Array, starting at the specified index of the target array.

Namespace:  System.Collections.ObjectModel
Assembly:  mscorlib (in mscorlib.dll)

Visual Basic (Declaration)
Public Sub CopyTo ( _
    array As T(), _
    index As Integer _
)
Visual Basic (Usage)
Dim instance As Collection
Dim array As T()
Dim index As Integer

instance.CopyTo(array, index)
C#
public void CopyTo(
    T[] array,
    int index
)
Visual C++
public:
virtual void CopyTo(
    array<T>^ array, 
    int index
) sealed
J#
public final void CopyTo(
    T[] array,
    int index
)
JScript
public final function CopyTo(
    array : T[], 
    index : int
)

Parameters

array
Type: array<T>[]()[]

The one-dimensional Array that is the destination of the elements copied from Collection<(Of <(T>)>). The Array must have zero-based indexing.

index
Type: System..::.Int32

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

Implements

ICollection<(Of <(T>)>)..::.CopyTo(array<T>[]()[], Int32)
ExceptionCondition
ArgumentNullException

array is nullNothingnullptra null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

index is equal to or greater than the length of array.

-or-

index is less than zero.

ArgumentException

The number of elements in the source Collection<(Of <(T>)>) is greater than the available space from index to the end of the destination array.

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

The elements are copied to the Array in the same order in which the enumerator iterates through the Collection<(Of <(T>)>).

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

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 2.0, 1.0
Page view tracker