开发者

Cast to GetType a object

Is ther开发者_运维百科e any way where i can cast a object to GetType() a object value?

such as:

object result = method.Invoke(instance, parametersValue); //method returnt int

i want result cast to int Dynamically.


There is no way to convert an object to its type with the Type object.

What you can do is use dynamic keyword and it will resolve the type in runtime.

dynamic result = method.Invoke(instance, parametersValue);


I don't understand the question, GetType() is not an object, is a method.

You can execute the sentence you wrote just as is it. To cast result back to int use:

int intVar = (int) result;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜