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

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

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

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

ROW  - COL  = 3
COL  = 4
COL  = 3
COL  = 255
COL  = 6
COL  = 0
Row  - COL  = 3
COL  = 4
COL  = 3
COL  = 255
COL  = 6
COL  = 0
``````

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

``````Debug.WriteLine(((byte[])weight[cnt-1]));
``````

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]);

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

ROW  - COL  = 3
COL  = 4
COL  = 3
COL  = 255
COL  = 6
COL  = 0
Row  - COL  = 3
COL  = 4
COL  = 3
COL  = 255
COL  = 6
COL  = 0
``````

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]));
``````
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  then I can run my script but then I can't access the value of  in the column.
Talk2:
Talk3:
that did the trick, lead the group down the wrong path by not knowing the Type of object. Thank you for researching. 