Programming languages can be divided in to two categories strongly typed and dynamically typed. Strongly typed languages are those where the checks happen during compile time while dynamic languages are those where type checks are bypassed during compile time. In dynamic language object types are known only during runtime and type checks are activated only at run time.
So we would like to take advantage of both the world. Because many times we do not know object type until the code is executed. In other words we are looking at something like dynamically statically typed kind of environment. That’s what dynamic keyword helps us with.
If you create a variable using the “Dynamic” keyword and if you try to see members of that object you will get a message as shown below “will be resolved at runtime”.
Now try the below code out. In the below code I have created a dynamic variable which is initialized with a string data. And in the second line I am trying to have fun by trying to execute a numeric incremental operation. So what will happen now ?.... think.
Now this code will compile fine without any complains. But during runtime it will throw an exception complaining that the mathematical operations cannot be executed on the variable as it’s a string type. In other words during runtime the dynamic object gets transformed from general data type to specific data type (ex: - string for the below code).
Also see following basic but important .NET interview questions video on Aggregation, Association and Composition