SiteMap  | About    

Dynamic type Vs Object type


Each object in C# is derived from object type , either directly or indirectly. It is compile time variable and require boxing and unboxing for conversion and it makes it slow. You can change value type to reference type and vice versa.


Object type variables require to cast object variable to original type before using it. It means values of any types can be stored in object type variable. But type conversion (un-boxing) is required to get original type when the value of variable is retrieved in order to use it. It's actually increasing the overhead when we do this both operation. Allows to perform operation of given type once it gets cast any user defined or primitive data type . Also, Object type is useful when it doesn't have more information about the data type.


Dynamic is run time variable and not require boxing and unboxing . You can assign and value to dynamic and also can change value type stored in same. All errors on dynamic can be discovered at run time only. We an also say that dynamic is a run time object which can hold any type of data.


For Dynamic type Casting is not required but you need to know the property and methods related to stored type. Dynamic type is useful when coding using reflection or dynamic language support or with the COM objects, because we require to write less amount of code. (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.