I have two arrays:
T[] array1D;
T[,] array2D;
They each have the same total number of elements.
If these arrays had the same number of dimensions, then I could simply use Array.Copy to copy data from one to the other. But since they have differing numbers of dimensions, I cannot, according to the MSDN documentation:
The sourceArray and destinationArray parameters must have the same number of dimensions.
Having profiled my code, I have determined that copying each element individually is too slow for my purposes. So, is there an alternative to Array.Copy that can copy between arrays of differing dimensions with performance similar to that of Array.Copy?
Thank you!
(edit) As requested, here is my code for copying each element individually:
int iMax = array2D.GetLength(0);
int jMax = array2D.GetLength(1);
int index = 0;
for(int i = 0; i < iMax; ++i)
{
for(int j = 0; j < jMax; ++j)
{
array1D[index] = array2D[i, j];
++index;
}
}