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

时间:2019-07-18 14:39:17

标签: arrays vb.net

我的代码

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()

........得到此错误:

  

'Byte()()'类型的值不能转换为'Byte()',因为'Byte()'不是从'Byte'派生的。

这是我从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()

1 个答案:

答案 0 :(得分:0)

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

Dim flatten As Byte() = b.SelectMany(Function(x) x.SelectMany(Function(y) y)).ToArray()
相关问题