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

馋奶兔 提交于 2020-01-05 02:53:47

问题


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


回答1:


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

Something closer to:

Public KeyList(15)() As Byte



回答2:


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.



来源:https://stackoverflow.com/questions/6619318/vb-net-how-to-get-reference-to-a-row-in-a-2d-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!