While going through the ASP.NET MVC docs I see this idiom being used alot:
new { foo = "bar", baz = "foo" }
Is this a Dictionary literal syntax?
Is it a new class/struct with the type inferred by the called function definition?
If it is how come the vars don’t need a type definition, not even var?
This is an anonymous type.
http://msdn.microsoft.com/en-us/library/bb397696.aspx
Anonymous types are strongly typed. From the perspective of the common language runtime, an anonymous type is no different from any other reference type.
If two or more anonymous types in the same assembly have the same number and type of properties, in the same order, the compiler treats them as the same type. They share the same compiler-generated type information.
Anonymous types should not be passed between assemblies or even as return values from methods (possible, but rarely, rarely advisable).
Anonymous types are a convenience mechanism, e.g. when working with LINQ, such as the following projection:
LINQ Example
Other Questions
No, though there are many similarities. ASP .Net MVC uses
RouteValueDictionaryand anonymous types to represent the same information in many method overloads.Value types are inferred, though inference is not always possible: http://msdn.microsoft.com/en-us/library/bb531357.aspx (VB version, if someone knows the URL of the c# equivalent please update)