Copy array to another array starting at the specified destination array index in CSharp
Description
The following code shows how to copy array to another array starting at the specified destination array index.
Example
/*from w ww. j av 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 );
foreach(string s in mySourceArray){
Console.WriteLine(s);
}
foreach(string s in myTargetArray){
Console.WriteLine(s);
}
}
}
The code above generates the following result.