Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy arrays from specific indexes

Tags:

arrays

c#

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 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};
like image 409
Mike Avatar asked Dec 07 '22 01:12

Mike


1 Answers

Is this what you're looking for?

Array.Copy(source, 0 /*start loc*/, destination, 3 /*start loc*/, 2 /*count*/);
like image 199
David Yaw Avatar answered Dec 09 '22 14:12

David Yaw