"If two or more anonymous types have the same number and type of properties in the same order, the compiler treats them as the same type and they share the same compiler-generated type information."
This is
not correct. In fact, the property names play into this as well, otherwise anonymous types would be dangerous. Look at this code:
var
type1 = new {lastName = "James", email = "junk@domain.com", age = 30};
var
type2 = new {companyName = "TechRepublic", domainName = "www.techrepublic.com", yearsInBusiness = 20 };
var
type1SecondVar = new { lastName = "Washington", email = "firstpres@whitehouse.gov", age = 200 };
Console
.WriteLine(type1.GetType());
Console
.WriteLine(type2.GetType());
Console
.WriteLine(type1SecondVar.GetType());
Console
.ReadLine();
It produces the following output:
<>f__AnonymousType0`3[System.String,System.String,System.Int32]
<>f__AnonymousType1`3[System.String,System.String,System.Int32]
<>f__AnonymousType0`3[System.String,System.String,System.Int32]
Clearly, the property names play into whether or not the compiler treats them as the same type.