Solved

Compare 2 list collections for equality

Posted on 2012-04-03
2
648 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 100 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

896 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now