Copy a range of Array starting at the first and paste into another Array starting at the first in CSharp
Description
The following code shows how to copy a range of Array starting at the first and paste into another Array starting at the first.
Example
//w w w. j a va 2 s. co 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, myObjArray, 2 );
foreach (int i in myIntArray ){
Console.WriteLine(i);
}
foreach (int i in myObjArray ){
Console.WriteLine(i);
}
}
}
The code above generates the following result.