.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> .Net Framework >> Post New Resource Bookmark and Share   

 Subscribe to Articles

What is Anonymous Type Equality in a tweak

Posted By:Gaurav Arora       Posted Date: April 28, 2009    Points: 25    Category: .Net Framework    URL: http://www.dotnetspark.com  

What is Anonymous Type Equality?


If two or more anonymous types have same order, number and member declaratory type and name then the same anonymous type is defined. So, its permissible to use the referential equality operator on these types.


Now let's see the other face of the coin, means of any of order, number and member declaratory type and name is different then different anonymous type is defined for each. Then it throws compiler error while testing referential integrity.



Here you can use reflection to get the type information of anonymous types.

Use the Equals method (defined by all objects) to test equality of members


Lets go through following lines:

var paternalMember = new {Father = "R k Arora", City = "Nangal Dam"};

var maternalMember = new {Mother = "Santosh Arora", City = "New Delhi"};


var fatherHome = new {Father = "R k Arora", City = "Nangal Dam"};

var motherHome = new {City = "New Delhi", Mother = "Santosh Arora"};


//Compare member equality:

paternalMember.Equals(fatherHome); //returns true

paternalMember.Equals(fatherHome); //error


 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend