【问题标题】:How to extract one-dimensional array from Two dimensional array in VB.NET如何从VB.NET中的二维数组中提取一维数组
【发布时间】:2013-06-03 14:41:09
【问题描述】:

H 我正在使用 VB.NET,并且我有一个二维数组。 如何从中提取一维数组?即第三行。

类似于 MAT[0] 之类的东西,我会在 java 中执行以从矩阵中获取第一行。

谢谢。

【问题讨论】:

  • 能否展示定义二维数组的代码片段?
  • 公共 RXUser_Array(14, 257) 作为字节。这就是它的声明方式。谢谢。

标签: arrays vb.net multidimensional-array


【解决方案1】:

用圆括号代替ob括号:

mat(0)

【讨论】:

  • 试过了。它说“索引数小于索引数组的维数”
  • 对不起。 is's mat(0)(0) 或者你想得到的索引。
【解决方案2】:

我认为你必须编写一个简单的函数来获取单行作为数组,例如:

Private Function GetRow(matrix As Byte(,), row_number As Integer) As Byte()
    'get the number of columns of your matrix
    Dim number_of_columns As Integer = matrix.GetLength(1)

    'define empty array, at the end of the 'for' cycle it will contain requested row's values  
    Dim values As Byte() = Nothing

    For i As Integer = 0 To number_of_columns - 1
        'Resize array
        ReDim Preserve values(i)
        'Populate array element
        values(i) = matrix(row_number, i)
    Next

    Return values

End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2013-07-30
    • 2013-05-14
    • 1970-01-01
    • 2018-12-22
    相关资源
    最近更新 更多