c# - 将 bool 的多维数组复制到另一个数组中

标签 c#

如何将 bool 的多维数组复制到其他数组中。一维数组使用长度,但我不确定这是否适用于多维数组。

bool[][] OldArray
bool[][] NewArray = new bool[][];

Array.Copy(NewArray,OldArray,NewArray.length)

最佳答案

那不是多维数组,而是锯齿状数组(数组的数组)。

bool[,] multiDimArray;

是多维的

bool[][] jaggedArray;

是锯齿状的。不同之处在于,多维数组始终为矩形,而锯齿状数组则不一定。

要复制多维数组(第一种情况),您只需将每个维度的长度相乘,因为(来自 MSDN):

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. For example, if an array has three rows (or columns) with four elements each, copying six elements from the beginning of the array would copy all four elements of the first row (or column) and the first two elements of the second row (or column).

对于锯齿形,您需要遍历第一个维度,然后依次Array.Copy 每个内部数组。

关于c# - 将 bool 的多维数组复制到另一个数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22078476/

相关文章:

c# - 从非泛型类的泛型方法派生泛型方法

c# - 推导十进制数后面的所有字符,前导 0

c# - 取消订阅子对象 Prop 更改事件

c# - Unity 2019 - 如何在运行时将混音器音频输出保存到音频剪辑或将新保存的 .wav 加载到音频剪辑?

c# - 将位图转换为 8bpp 灰度输出作为 c# 中的 8bpp 彩色索引

c# - 如何更改 TabControl 中所选选项卡的颜色?

c# - ASP.NET MVC 5 web.config <system.web> 编译 & httpRuntime 错误

c# - 如何在 EF7(Core) 中创建与同一个表的多个关系?

c# - PowerShell - 从 .csproj 文件获取版本

c# - 抛出另一个异常的异常