Quick sanity check. Is Array.Copy for one dimensional arrays only, or can it handle more?
When reading the specs I read it (probably wrongly) to mean that the match must occur on the second dimension. ie. the source and destination indexes can be different, and we can specify the number of elements.
Okay, so lets hone in on “match”. For an array of rank 2 getting copied to another arry of rank 2, say 10×4 to 20×4, are we saying that we must match on dimensions one and two, or two only. I need it to be on the second dimension only.
Is the only way to achieve this with a looping mechanism in .net. If so, that’s going to be a lot slower than a block copy.
Check this out:
static void Main(string[] args)
{
var A = new int[2,4] {{1, 1, 1, 1}, {2, 2, 2, 2}};
var B = new int[4,4];
var C = new int[4, 4];
Array.Copy(A, 0, B, 4, 8);
Array.ConstrainedCopy(A, 0, C, 8, 8); // haven't noticed this method before. Same behaviour though.
}
Notice that we have to specify the correct starting point in a one dimensional view of the world. I didn’t expect this.
It supports single and multi-dimensional as long as the source and destination match.
http://msdn.microsoft.com/en-us/library/k4yx47a1.aspx
EDIT:
Think of match in the way it lays out “end to end”. A two dimensional array is really just consecutive memory blocks – a 3 x 4 = 12 blocks. When it copies, it’s going to copy the layout – the end to end layout. The key is the line where they say it’s conceptually laid end to end.