Monday, May 17, 2010

Dynamic type in c# 4.0

Due to the languages like pyhton,ruby and growing technologies Microsoft introduced a new keyword name Dynamic in c# 4.0, we have var keyword for somehow same purpose.

The dynamic capabilities of C# 4 are part of the Dynamic Language Runtime (DLR). The DLR is
a set of services that is added to the CLR to allow the addition of dynamic languages such as Ruby and Python. It also allows C# to take on some of the same dynamic capabilities that these dynamic languages have.

There is a version of the DLR that is open source and resides on the CodePlex web site. This
same version is included with the .NET 4 Framework, with some additional support for language
implementers.

In the .NET Framework, the DLR is found in the System.Dynamic namespace as well as a few
additional classes in the System.Runtime.CompilerServices namespace.
IronRuby and IronPython, which are open source versions of the Ruby and Python languages, use the DLR. Silverlight also uses the DLR. It ’ s possible to add scripting capabilities to your applications by hosting the DLR. The scripting runtime allows you to pass variables to and from the script.

The Dynamic type will allow developer to assign any datatype instance without worrying about casting.

like
dynamic dn = new Person();


Limitations:

1] You cant query dynamic variable using Linq,
2] Even not supports Extension methods

regards

"Please give me your valuable comments to improve my knowledge :) "

No comments:

Post a Comment