简体   繁体   中英

Runtime dynamic for object property

in order to determine my class type on Run-time i am using dynamic :

dynamic dynamic = new MyClass();
dynamic.SomeMethod();

So this work fine and all good, the problem is that if i want to reach this object property and in this case it seems that this is not possible:

dynamic.MyProperty;

Error 1 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

Any solution ?

dynamic.MyProperty;

Is not a statement you can't use it in this way. Instead you can do something like this:

 var abc = dynamic.MyProperty;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM