Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Compare 2 list collections for equality

Posted on 2012-04-03
2
Medium Priority
?
686 Views
Last Modified: 2013-12-27
I need to compare two custom object lists to see if they both contain the same objects. Each object has an Id property. The lists will not contain duplicates and may not be the same length.
0
Comment
Question by:ifetayo
2 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 400 total points
ID: 37802188
Please try:
bool isEqual = (list1.Count == list2.Count)
            && (list1.TrueForAll( e1 => list2.Any(e2 => e2.Id == e1.Id)));

Open in new window

0
 

Author Closing Comment

by:ifetayo
ID: 38002970
Sorry so late with this. I must have figured out a way to solve my problem shortly after asking this question, but for the life of me, I can't remember what I did. This is a good solution though and I have no doubt that it would work so I'm going to award the points anyway. Thanks a bunch.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Loops Section Overview
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question