I have two collections of objects (List list1 and List list2). There is a property on each called "ID". I know that list2 will always have more items than list1, I just need an easy way to get a collection of all the items that exist in list2 but not list1 using LINQ lambda expressions.
LINQ Lambda – Find all ID’s in one list that don’t exist in another list
lambdalinq
Related Topic
- C# – LINQ’s Distinct() on a particular property
- C# – Sorting a list using Lambda/Linq to objects
- C# – How to use LINQ to select object with minimum or maximum property value
- C# – Distinct() with lambda
- .net – LINQ: When to use SingleOrDefault vs. FirstOrDefault() with filtering criteria
- C# – IEnumerable vs List – What to Use? How do they work
- C# – Use LINQ to get items in one List<>, that are not in another List<>
- C# – reason for C#’s reuse of the variable in a foreach
Best Answer
If you only need the IDs of the items then Mark's answer will do the trick nicely. If you need to return the items themselves (and they don't already have a suitable
Equals
implementation) then you could try something like this: