Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

H I'm using VB.NET, and i have a two dimensional array. How do I extract a one-dimensional array from it? I.E the 3rd row.

Something like MAT[0] which i would do in java to get the first row from a matrix.

Thanks.

share|improve this question
3  
Can you show the code fragment where you define the 2 dimensional array? – Andrea Jun 3 '13 at 15:07
    
Public RXUser_Array(14, 257) As Byte. That's how it's declared. Thanks. – Eyal D Jun 3 '13 at 15:11

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
share|improve this answer

Use parenthesis instead ob brackets:

mat(0)
share|improve this answer
    
Tried that. It says "number of indices is less than the number of dimensions of the indexed array" – Eyal D Jun 3 '13 at 14:57
    
Sorry. is's mat(0)(0) or the index you want to get. – Oscar Jun 3 '13 at 15:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.