CODEDIGEST InstallShield
Home Articles CodeDigest Tutorials InstallShield FAQs
Skip Navigation LinksHome » Article » .Netframework Article » How to Test Anonymous Type Equality - LINQ: A Step Ahead Series  Submit Articles and Win Geeky Prizes!!   You are not logged in.
Search
 

Sponsors
InstallShield
 

Product Spotlight
 

Technologies
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
Testing Anonymous Type Equality in LINQ
Free Trial: InstallShield 2010 for Windows Installers Is InstallShield right for you? InstallShield handles your most complex installation requirements in minutes. Try it now.

By Gaurav Arora
Posted On Mar 05,2009
Article Rating: (Login)
Be first to rate
this article.
No of Comments: 0
Category: C#
Print this article.

Subscribe to our feed!

Testing Anonymous Type Equality in LINQ

 

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.

 

Note

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

 

If you want to know more about Anonymous Type-LINQ please refer to Anonymous Types in LINQ.

You can contribute to CodeDigest.Com:
Donate to CodeDigest.com
Article Feedback
Title  
Submitted By  
Comment  
Enter the verification number
 
Comments