Copy ArrayList to Array, starting at specific index of the target array in CSharp
Description
The following code shows how to copy ArrayList to Array, starting at specific index of the target array.
Example
/*w w w. j a v a 2s . co m*/
using System;
using System.Collections;
public class SamplesArrayList {
public static void Main() {
ArrayList mySourceList = new ArrayList();
mySourceList.Add( "A" );
mySourceList.Add( "B" );
mySourceList.Add( "C" );
mySourceList.Add( "D" );
mySourceList.Add( "E" );
mySourceList.Add( "F" );
String[] myTargetArray = new String[15];
myTargetArray[0] = "0";
myTargetArray[1] = "1";
myTargetArray[2] = "2";
myTargetArray[3] = "3";
myTargetArray[4] = "4";
myTargetArray[5] = "5";
myTargetArray[6] = "6";
myTargetArray[7] = "7";
myTargetArray[8] = "8";
foreach(string s in myTargetArray){
Console.WriteLine(s);
}
// Copies the entire source ArrayList to the target Array starting at index 6.
mySourceList.CopyTo( myTargetArray, 6 );
foreach(string s in myTargetArray){
Console.WriteLine(s);
}
}
}
The code above generates the following result.