Copy a range of an Array from index and paste them to another Array at the specified index in CSharp
Description
The following code shows how to copy a range of an Array from index and paste them to another Array at the specified index.
Example
/*w w w.j a v a2s. c o m*/
using System;
public class SamplesArray {
public static void Main() {
Array myIntArray=Array.CreateInstance( typeof(System.Int32), 5 );
for ( int i = myIntArray.GetLowerBound(0); i <= myIntArray.GetUpperBound(0); i++ ){
myIntArray.SetValue( i+1, i );
Console.WriteLine(i+1);
}
Array myObjArray = Array.CreateInstance( typeof(System.Object), 5 );
for ( int i = myObjArray.GetLowerBound(0); i <= myObjArray.GetUpperBound(0); i++ ){
myObjArray.SetValue( i+26, i );
Console.WriteLine(i+26);
}
Array.Copy( myIntArray, myIntArray.GetLowerBound(0), myObjArray, myObjArray.GetLowerBound(0), 1 );
foreach (int i in myIntArray ){
Console.WriteLine(i);
}
foreach (int i in myObjArray ){
Console.WriteLine(i);
}
}
}
The code above generates the following result.