简体   繁体   English

如何从VB.NET中的二维数组中提取一维数组

[英]How to extract one-dimensional array from Two dimensional array in VB.NET

H I'm using VB.NET, and i have a two dimensional array. H我正在使用VB.NET,并且我有一个二维数组。 How do I extract a one-dimensional array from it? 如何从中提取一维数组? IE the 3rd row. IE浏览器的第三行。

Something like MAT[0] which i would do in java to get the first row from a matrix. 像MAT [0]一样,我会在java中执行以从矩阵中获取第一行。

Thanks. 谢谢。

使用括号代替圆括号:

mat(0)

I think you have to write a simple function to get a single row as an array, for example: 我认为您必须编写一个简单的函数以将一行作为数组,例如:

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

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

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