M
Mark Smith
I'm trying to copy data from a 1D array to a 2D array.
The obvious thing doesn't work:
int[,] twoDee = new int[2,2];
int[] oneDee = new int[2] { 1, 2 };
Array.Copy(oneDee, 2, twoDee, 2, 2);
This causes a RankException. But the MSDN documentation says:
When copying between multidimensional arrays, the array
behaves like a long one-dimensional array, where the rows
(or columns) are conceptually laid end to end.
This seems to suggest that there should be some way to accomplish
this, but I can't find any other syntax that's acceptable. I can
do it using a jagged 2D array, but I really wanted to avoid creating
lots of 1D subarray objects. Anybody know the trick?
The obvious thing doesn't work:
int[,] twoDee = new int[2,2];
int[] oneDee = new int[2] { 1, 2 };
Array.Copy(oneDee, 2, twoDee, 2, 2);
This causes a RankException. But the MSDN documentation says:
When copying between multidimensional arrays, the array
behaves like a long one-dimensional array, where the rows
(or columns) are conceptually laid end to end.
This seems to suggest that there should be some way to accomplish
this, but I can't find any other syntax that's acceptable. I can
do it using a jagged 2D array, but I really wanted to avoid creating
lots of 1D subarray objects. Anybody know the trick?