Work with the object

consider the variable ob4, as shown in the figure. variable ob4

now: how can I achieve ob4 [0] β†’ [0,2]

var o=ob4[0]; double[,] p=(double[,]) o[0,0]; 

the line (double [,] p = (double [,]) o [0,0];) gives the following error:
Cannot apply indexing with [] to an expression of type "object"

+6
source share
2 answers

First you need to discard o[0, 0] in object[,] :

 var o = (object[,]) ob4[0]; double[,] p = (double[,]) o[0, 0]; 

It would be better if you could avoid all of these nested multidimensional arrays with so little type information at compile time - you didn't give us much context, but if you could change your object model, that would help a lot.

+9
source

Well, the error message shows that the runtime o is equal to object , not object[,] . Therefore, you can change your code to:

 double[,] = (double[,])((object[,])o)[0,0]; 

Now the runtime knows that o should be considered as object[,] .

+1
source

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


All Articles