VS 2010 introduce a new variable type which is dynamic.
By the name it is clear that it will have dynamic property means what will be the data type will be decide at run time.
Suppose if I declare dynamic Name = “rajat”
Then Name variable considered as a string variable
Simillarly dynamic Age = 21
Then Age variable is considered as integer.
To understand it more lets follow the example below.
I have declared a test variable which is dynamic type and on each line I assign a different value to the variable as shown in below fig.
When you run this set of statements you will find following result.
The first variable assignment is considered as integer, the second variable assignment is considered as a string and after last value which is date time variable considered as datatime variable.
So we have seen at each assignment of the value the nature of variable is also changed which is so dynamic that’s why the name it is called dynamic variable type. It Means it bypass compiler time checking.
I hope it give some hit how to use dynamic and where we can use it.
Thanks & best regards,