Search This Blog

Friday, December 19, 2014

Dynamic Type C# Example

C# > Types > dynamic

The dynamic enables bypass compile-time type checking. These operations are resolved at run time. 
Example

dynamic dyn = 1;
object obj = 1;

var dyn_type = dyn.GetType(); // System.Int32
var obj_type = obj.GetType(); // System.Int32

dyn = dyn + 1; //Ok
obj = obj + 1; // Error    1      Operator '+' cannot be applied to operands of type 'object' and 'int'