开发者

Copy arrays from specific indexes

How can I copy an array of values to a destination array starting from a specific index without looping?

For example,if I have an array with 2 values, I have to copy those two elements to another array which开发者_JAVA技巧 has a capacity of 5 starting from index 3?

 double[] source = new double[] {1, 2};
 double[] destination = new double[5]{0,0,0,0,0};
 //How to perform this copy?
 double[] result = new double[5] {0, 0, 0, 1, 2};


Is this what you're looking for?

Array.Copy(source, 0 /*start loc*/, destination, 3 /*start loc*/, 2 /*count*/);


Use Array.CopyTo or the static method Array.Copy.

source.CopyTo(destination, 3);


double[] source = new double[] {1, 2};
 double[] destination = new double[5]{0,0,0,0,0};
 //How to perform this copy?
ArrayList result = new ArrayList();
result.AddRange(source);
result.AddRange(destination);
destination = result.ToArray();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜