Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Compare 2 list collections for equality

Posted on 2012-04-03
2
Medium Priority
?
683 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 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Let me explain this picture a little bit.  First, in case you haven't already guessed, you are looking at my 2 phones, an Android Samsung Galaxy S5 on the left and an iPhone 5 on the right.  They are on their respective cradles on my desk.  But, you…
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 video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

688 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