C# Tutorials: Difference between Object datatype and Dynamic datatype

Object:
• “Object” data type references any type of data
• To apply arithmetic operations on the data, that is declared as object type ,data should be converted to specific data type.
• And then only ,applying arithmetic operators is possible

Example for Object:
object n = 10; //variable declared as object
n *= 10;//showing Immediate ERROR.so Exclude this statement.
int num;
num = (int) n; // Casting object type to integer type
num *= 10;
Dynamic:
• Dynamic data type also holds any type of data
• When data is declared as dynamic ,there is no need to convert the data declared as dynamic to specific data,to apply arithmetic operations.
• This keyword is introduced in .NET framework 4.0
Example for Dynamic:
dynamic x = ".NET Framework ";//Variable declared as dynamic
x += "Version 4.0";//No need to cast to specific data type




Get to know more about such datatypes at bestdotnettraining

Comments