C# 里的Array.CopyTo复制一个数组的部分到另外一个数组
using System; public class CopyToArray { public static void Main() { object[] objects1 = {"one", "two", "three"}; object[] objects2 = {0, 1, 2, 3, 4, 5}; Console.Write ("objects1 array elements: "); foreach(object o in objects1) { Console.Write ("{0} ", o); } Console.Write ("\nobjects2 array elements: "); foreach (object o in objects2) { Console.Write ("{0} ", o); } objects1.CopyTo (objects2, 1); Console.Write ("\nobjects2 array elements: "); foreach (object o in objects2) { Console.Write ("{0} ", o); } Console.WriteLine(); } }
这段代码的执行结果如下:
objects1 array elements: one two three objects2 array elements: 0 1 2 3 4 5 objects2 array elements: 0 one two three 4 5