c# - Declare a variable using a Type variable -
i have code:
type lefttype = workitem[leftfieldname].gettype();
i want declare variable of type:
lefttype somevar;
is possible?
you can these , cast them known interface.
var somevar = convert.changetype(someoriginalvalue, workitem[leftfieldname].gettype()); var somevar = activator.createinstance(workitem[leftfieldname].gettype());
if replace var
dynamic
(and using .net 4), can call methods expect on somevar object. if don't exist, you'll missingmethodexception.
Comments
Post a Comment