Array.CopyTo Method (Array, Int32)
Copies all the elements of the current one-dimensional array to the specified one-dimensional array starting at the specified destination array index. The index is specified as a 32-bit integer.
Assembly: mscorlib (in mscorlib.dll)
abstract CopyTo : array:Array * index:int -> unit override CopyTo : array:Array * index:int -> unit
- Type: System.Array
The one-dimensional array that is the destination of the elements copied from the current array.
- Type: System.Int32
A 32-bit integer that represents the index in array at which copying begins.
array is a null reference (Nothing in Visual Basic).
index is less than the lower bound of array.
array is multidimensional.
The number of elements in the source array is greater than the available number of elements from index to the end of the destination array.
The type of the source Array cannot be cast automatically to the type of the destination array.
The source array is multidimensional.
At least one element in the source Array cannot be cast to the type of destination array.
This method copies all the elements of the current array instance to the array destination array, starting at index index. The array destination array must already have been dimensioned and must have a sufficient number of elements to accommodate the copied elements. Otherwise, the method throws an exception.
If this method throws an exception while copying, the state of array is undefined.
This method is an O(n) operation, where n is Length. It performs a shallow copy only.
The following code example shows how to copy an Array to another Array with a nonzero lower bound. Note that the entire source Array is copied, including empty elements that overwrite existing elements in the target Array.
.NET FrameworkSupported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
.NET for Windows Phone appsSupported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.