How to access an object by c # index

I have a foreach loop in C # that returns some inventory data, the property is location_idreturned as object[]. cycle as follows:

foreach (XmlRpcStruct item in result)
{
   object obj =  item["location_id"];
}

in the debugger, I see the object as follows: enter image description here

so I think the object is something like

obj[0] = 12
obj[1] = "WH/Stock"

I tried to access objhow obj[0], then I get

Cannot apply indexing with [] to an expression of type 'object'

So, how can I access an object by index to get values ​​like 12andWH/Stock

+4
source share
2 answers

obj [], :

var list = (object[])obj;

list[0].

+6

:

object[] obj =  item["location_id"];

, , :

var obj =  item["location_id"];
+1

Source: https://habr.com/ru/post/1662496/


All Articles