- In case of var type is decided at compile time by compiler=>Complie time Type Interference.
- var is a strongly implicitly typed local variable for which the compiler is able to determine the type from the initialization expression.
- Introduced in 3.5
- In case of dynamic type is decided at runtime=>Run time Type Interference.
string MyString="Sukesh Marla"; var MyVarVariable=MyString; Response.Write(MyVarVariable.MyMethod());when we run the above code,we get a error 'string does not contain a definition for 'MyMethod' and no extension method 'MyMethod' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?
means var knows that what is assgned to it.
string MyString="Sukesh Marla"; dynamic MyVarVariable=MyString; Response.Write(MyVarVariable.MeMethod());
this will get complied.
and throws exception at runtime,if you wont define any extension method MyMethod for string class.