using System; namespace array { public class SamplesArray { public static void Main() { //创建新的整型数组并进行初始化 int[] IntArray=new int[5]{1,2,3,4,5}; object[] ObjArray=new object[5]{26,27,28,29,30}; //显示两个数组的初始值 Console.Write("初始化数组:"); PrintValues(IntArray); Console.Write("初始化对象数组:"); PrintValues(ObjArray); Array.Copy(IntArray,ObjArray,2); Console.Write("显示整型数组:"); PrintValues(IntArray); Console.Write("显示对象数组:"); PrintValues(ObjArray); Array.Copy(ObjArray,ObjArray.GetUpperBound(0)-1,IntArray,IntArray.GetUpperBound(0)-1,2); Console.Write("显示整型数组:"); PrintValues(IntArray); Console.Write("显示对象数组:"); PrintValues(ObjArray);
} public static void PrintValues(Object[] Arr) { foreach(Object i in Arr) { Console.Write("\t{0}",i); } Console.WriteLine(); } public static void PrintValues(int[] Arr) { foreach(int i in Arr) { Console.Write("\t{0}",i); } Console.WriteLine(); } } }