在c#中为多维数组添加维度

时间:2020-12-03 21:36:14

I have a multidimensional array

我有一个多维数组

byte[,] matrix;

and i want copy in a 3 dimension array

我希望复制三维数组

byte[,,] 3dplan; 

in this way

通过这种方式

3dplan[,,0]=matrix

What is the fastest way to accomplish this task in c#?

在c#中完成此任务的最快方法是什么?

1 个解决方案

#1


5  

You need to manually copy the elements in a nested loop; there is no faster way.

您需要在嵌套循环中手动复制元素;没有更快的方法。

If you switch to a jagged array (byte[,][] or byte[][][]), you can insert the smaller array as-is into a slot in the larger array (although they will both refer to the same array instance and will pick up changes)

如果切换到锯齿状数组(byte [,] []或byte [] [] []),则可以将较小的数组原样插入较大数组的插槽中(尽管它们都将引用相同的数组实例并将获取更改)

#1


5  

You need to manually copy the elements in a nested loop; there is no faster way.

您需要在嵌套循环中手动复制元素;没有更快的方法。

If you switch to a jagged array (byte[,][] or byte[][][]), you can insert the smaller array as-is into a slot in the larger array (although they will both refer to the same array instance and will pick up changes)

如果切换到锯齿状数组(byte [,] []或byte [] [] []),则可以将较小的数组原样插入较大数组的插槽中(尽管它们都将引用相同的数组实例并将获取更改)