处理作为复杂数组返回的数据

Working with data returned as a Complex Array
2020-10-22
  •  译文(汉语)
  •  原文(英语)

如果我的术语不正确,请多多包涵.

我正在尝试从对象中提取数据.该对象具有一个复杂的数组,该数组由行和每行6列组成.

我需要访问数组中的最后一行,所以我在使用.Count.问题是无法访问行中的列.这是代码:

           var weight = USBHIDDRIVER.USBInterface.usbBuffer;
           var cnt = weight.Count;
           Debug.WriteLine(weight[cnt][4]);

USBHIDDRIVER.USBInterface.usbBuffer; contains data in the following format:

ROW [0] - COL [0] = 3
          COL [1] = 4
          COL [2] = 3
          COL [3] = 255
          COL [4] = 6
          COL [5] = 0
Row [1] - COL [0] = 3
          COL [1] = 4
          COL [2] = 3
          COL [3] = 255
          COL [4] = 6
          COL [5] = 0

等等,谢谢.

速聊1:
有什么例外?您还确定计数大于0吗?
速聊2:
使用cnt - 1var cnt = weight.Count - 1;
速聊3:
我收到的错误是"无法将带有[]的索引应用于类型对象的表达式"
速聊4:
计数很好,我收到了代表行的正确值.
速聊5:
并且您是否已验证weight是二维数组?
解决过程1

因为在这里访问基于零的列表,所以您应该使用索引数组的最后一个字段Count - 1.

USBHIDDRIVER.USBInterface.usbBuffer是一个ArrayList,因此它的元素是type object.要访问byte[]添加到此列表中的type元素,您将必须将元素转换为byte[]:

Debug.WriteLine(((byte[])weight[cnt-1])[4]);
速聊1:
感谢Peter的答复,问题是我在VS中收到以下错误"无法将带有[]的索引应用于类型对象的表达式",因此无法编译.如果删除[4],则可以运行脚本,但是无法访问该列中的[4]值.
速聊2:
看看USBHIDDRIVER并更新了我的答案.
速聊3:
做到了这一点,就通过不知道对象的类型将小组引向错误的道路.感谢您的研究.

Please bear with me if my terminology is incorrect.

I'm attempting to extract data from an object. The object has a complex array which consist of rows and 6 columns per row.

I need to access the very last row in the array so I'm using .Count. The problem is a can't access the columns within the row. Here is the code:

           var weight = USBHIDDRIVER.USBInterface.usbBuffer;
           var cnt = weight.Count;
           Debug.WriteLine(weight[cnt][4]);

USBHIDDRIVER.USBInterface.usbBuffer; contains data in the following format:

ROW [0] - COL [0] = 3
          COL [1] = 4
          COL [2] = 3
          COL [3] = 255
          COL [4] = 6
          COL [5] = 0
Row [1] - COL [0] = 3
          COL [1] = 4
          COL [2] = 3
          COL [3] = 255
          COL [4] = 6
          COL [5] = 0

etc, etc. Thanks in advance.

Talk1:
What is the exception? Also did you make sure count is greater than 0?
Talk2:
Use cnt - 1 or var cnt = weight.Count - 1;
Talk3:
the error I receive is "Cannot apply indexing with [] to an expression of type object"
Talk4:
the count is good, I'm receiving the correct value that represents the rows.
Talk5:
And have you verified that weight is a 2-dimensional array?
Solutions1

Because accessing a zero based List here, so you should be indexing the last field of the array using Count - 1.

USBHIDDRIVER.USBInterface.usbBuffer is an ArrayList, so it's elements are of type object. To have access to the elements of type byte[] that were added to this list, you will have to typecast the elements to byte[]:

Debug.WriteLine(((byte[])weight[cnt-1])[4]);
Talk1:
Thanks for the response Peter, the problem is I'm receiving the following error in VS "Cannot apply indexing with [] to an expression of type object" so I can't compile. If I remove the [4] then I can run my script but then I can't access the value of [4] in the column.
Talk2:
Just had a look at USBHIDDRIVER and updated my answer.
Talk3:
that did the trick, lead the group down the wrong path by not knowing the Type of object. Thank you for researching.
转载于:https://stackoverflow.com/questions/30597414/working-with-data-returned-as-a-complex-array

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入