C# Array CopyTo(Array, Int32)
Description
Array CopyTo(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.
Syntax
Array.CopyTo(Array, Int32)
has the following syntax.
public void CopyTo(
Array array,
int index
)
Parameters
Array.CopyTo(Array, Int32)
has the following parameters.
array
- The one-dimensional array that is the destination of the elements copied from the current array.index
- A 32-bit integer that represents the index in array at which copying begins.
Returns
Array.CopyTo(Array, Int32)
method returns
Example
The following code example shows how to copy an Array to another Array.
// w w w . ja v a2 s. c om
using System;
public class SamplesArray {
public static void Main() {
Array mySourceArray=Array.CreateInstance( typeof(String), 6 );
mySourceArray.SetValue( "three", 0 );
mySourceArray.SetValue( "napping", 1 );
mySourceArray.SetValue( "cats", 2 );
Array myTargetArray=Array.CreateInstance( typeof(String), 15 );
myTargetArray.SetValue( "The", 0 );
myTargetArray.SetValue( "quick", 1 );
myTargetArray.SetValue( "brown", 2 );
myTargetArray.SetValue( "fox", 3 );
mySourceArray.CopyTo( myTargetArray, 2 );
}
}
The code above generates the following result.