What are the real differences between anonymous type(var) in c# 3.0 and dynamic type(dynamic) that is coming in c# 4.0?
The dynamic
type is essentially object
, but will resolve all method / property / operator etc calls at runtime via the DLR or other provider (such as reflection).
This makes it much like VB with Option Strict Off, and makes it very versatile for calling into COM, or into DLR types.
There is no type checking at compile time with dynamic; convesely, anonymous types are proper static-typed, type-checked beasts (you can see them in reflector, although they aren't pretty).
Additionally, anonymous types can be handled exclusively by the compiler; dynamic
requires extensive runtime support - so anonymous types are a C# feature, but dynamic
will largely be implemented by .NET 4.0 (with some C# 4.0 support).