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;
精彩评论