Solved

Compare 2 list collections for equality

Posted on 2012-04-03
2
677 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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