Anonymous type Object Initializers
What is Anonymous Type of Object Initializers in .NET
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hemant KumarPosted Oct 20, 2011, 12:24 AM
Anonymous types are a new language feature introduced in the C# 3.0 release. For those that remember your set theory, an anonymous type is described as a tuple type that is automatically inferred and created from its object initializer. An object initializer specifies the values from one or more fields (or properties) of an object. Another way to look at this is that the object initializer specifies the named parameters that passed to an object.
All of this happens at compile time, so anonymous types are still strongly typed. In reality, the compiler automatically creates a class that represents the anonymous type. For example,
var product =new{Name ="C# Rocks!", Price = 3};automatically gets translated by the compiler to something that looks likethis:class__Anonymous1{privatestringname;privateintprice;publicstringName{get{returnname; }set{ name = value; }}publicintPrice{get{returnprice; }set{ price = value; }}}__Anonymous1 product =new__Anonymous1();product.Name ="C# Rocks!";product.Price = 3;While anonymous types might not seem all that useful on the surface, they are the cornerstone for LINQ. Without anonymous types, LINQ would not be able to create types dynamically. This is what allows LINQ to query for an arbitrary set of data, without first having the structure declared.
refer this links
http://www.dotnetfunda.com/articles/article1479-object-initializers-in-net-framework-.aspx
http://weblogs.asp.net/dwahlin/archive/2007/09/09/c-3-0-features-object-initializers.aspx