C# Array CopyTo(Array, Int64)
Description
Array CopyTo(Array, Int64)
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 64-bit integer.
Syntax
Array.CopyTo(Array, Int64)
has the following syntax.
[ComVisibleAttribute(false)]// w ww . j a v a 2s .c om
public void CopyTo(
Array array,
long index
)
Parameters
Array.CopyTo(Array, Int64)
has the following parameters.
array
- The one-dimensional array that is the destination of the elements copied from the current array.index
- A 64-bit integer that represents the index in array at which copying begins.
Returns
Array.CopyTo(Array, Int64)
method returns
Example
The following code example shows how to copy an Array to another Array.
/* ww w . j a v a2 s .c om*/
using System;
public class SamplesArray {
public static void Main() {
// Creates and initializes two new Arrays.
Array mySourceArray=Array.CreateInstance( typeof(String), 6 );
mySourceArray.SetValue( "A", 0 );
mySourceArray.SetValue( "B", 1 );
mySourceArray.SetValue( "C", 2 );
mySourceArray.SetValue( "D", 3 );
Array myTargetArray=Array.CreateInstance( typeof(String), 15 );
myTargetArray.SetValue( "The", 0 );
myTargetArray.SetValue( "quick", 1 );
myTargetArray.SetValue( "brown", 2 );
myTargetArray.SetValue( "fox", 3 );
myTargetArray.SetValue( "jumps", 4 );
myTargetArray.SetValue( "over", 5 );
mySourceArray.CopyTo( myTargetArray, 6 );
}
}
The code above generates the following result.