“dynamic” new feature in .NET 4.0 , How to use it ?

Dear Friends,
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.

dynamic Variable Example

When you run this set of statements you will find following result.

dynamic Variable Type 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,
Rajat Jaiswal


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s