VB .NET: How to get reference to a row in a 2D-arr

2019-07-18 14:37发布

I have a function that returns a 1D-array like this:

Public Function KeyConvert([args]) As Byte()

and a 2 dimension array:

Public KeyList(15, 5) As Byte

Which can be seen as 15 rows,each row is a 5 element array, as we all already knew.

Now I want to call the function and assign the result (which is a 1D array) to a row (say row 4) in the KeyList array. At first I thought the code should be like

Keylist(4) = KeyConvert([args])

But that didn't work. I cannot find a way to reference to that specific row.

So anybody have any idea? Thank you very much

2条回答
萌系小妹纸
2楼-- · 2019-07-18 15:18

There is no notion in VB.Net (or C#) of "a row" (or "a column") in a 2-dimensional array. Array elements in .Net can only be accessed one at a time.

If you make your KeyList variable be a one-dimensional array of 5-element arrays, then you will be able to use the syntax you showed.

If you need to keep KeyList as a 2-dimensional array so that you can more easily access any single "point" within it, then you can write a method that is passed the row to update and the 5-element array whose elements are to be copied, and have that method copy the 5 values one at a time into the respective columns.

查看更多
太酷不给撩
3楼-- · 2019-07-18 15:39

You want a jagged array, not a m-d one.

Something closer to:

Public KeyList(15)() As Byte
查看更多
登录 后发表回答