Most Viewed

Most Viewed

Saturday, 11 August 2012

C#4.0 Dynamic Vs Var keyword


C#4.0 Dynamic Vs Var keyword


In C # 4.0, There is a new keyword called dynamic, We can use ia as any datatype like float,int,string, double etc.

Actually we can implement the samething using Var keyword also, But there is a different behavior.

If you want to declare a variable of type with the var keyword, var implicitly static, I'll explain its meaning.

When we declare a string of some data (initialization that is) must be of type String and then the compiler  will use reflection to get all info about the type at the compile time.
See the example given Below:


Now Here we declared a string 

 Var someStr = "Example Some String ";
Response.Write(SomeStr.Length);
Var Keyword Implementation
 Similarly if we use dynamic keyword, It behaves like a Object
Dynamic Keyword Implementation













 We can access methods,properties,operators using Dynamic Keyword

According to the MSDN blog “Variables declared with var are implicitly but statically typed. Variables declared with dynamic are dynamically typed. This capability was added to the CLR in order to support dynamiclanguages like Ruby and Python.”







Read more ...