get values from object of value object[4,4]
(C# in VS2010)
I get an object from a method called multiplyMatrix(m1,m2)
.
The signature of this method is: public object multiplyMatrix(object[,] m1, object[,] m2)
Then,
object toCheckOutput = multiplyMatrix(m1, m2);
This row works, but I have to verify the data in the "array". When I watch the variable toCheckOutput in the watch window i get as value {object[4,4]}
and as type object{object[,]}
.
If I try to access a value of the "array" with toCheckOutput[0,1]
, I get the following error from the compiler:
Cannot apply indexing with [] t开发者_开发技巧o an expression of type 'object'.
Does somebody know how to solve this? I tried it with typecasts over typecasts but this didn't work either.
It sounds like the method signature should be public object[,] multiplyMatrix(object[,] m1, object[,] m2)
. If you have control over this API, fix it there.
If not, just cast around the problem:
object[,] toCheckOutput = (object[,])multiplyMatrix(m1, m2);
The compiler isn't letting you index object
because object
has no indexer; you need to make sure the compiler knows that the object is in fact an array.
精彩评论