简体   繁体   English

vb.net如何将3维数组展平为一维

[英]vb.net how to flatten 3 dimensional array into single dimension

My code 我的密码

Dim b()()() As Byte = New Byte(1)()() {New Byte()() {New Byte() {1, 2, 3}, New Byte() {4, 5, 6, 7}}, 
                                       New Byte()() {New Byte() {1, 2, 3}, New Byte() {4, 5, 6, 7}}}
' Put all arays into a single array.
Dim flatten As Byte() = b.SelectMany((Function(x) x) x).ToArray()

........gets this error: ........得到这个错误:

Value of type 'Byte()()' cannot be converted to 'Byte()' because 'Byte()' is not derived from 'Byte'. 类型'Byte()()'的值不能转换为'Byte()',因为'Byte()'不是从'Byte'派生的。

Here's the example of how to do it with 2 dimensions, that I got from another guy on StackO. 这是我从StackO的另一个人那里得到的二维尺寸的示例。

Dim a()() As Byte = New Byte(1)() {New Byte() {1, 2, 3}, New Byte() {4, 5, 6, 7}}
' Put all arays into a single array.
Dim flatten As Byte() = a.SelectMany(Function(x) x).ToArray()

您只需添加另一个SelectMany ,就像这样。

Dim flatten As Byte() = b.SelectMany(Function(x) x.SelectMany(Function(y) y)).ToArray()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM