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.
相关问题
- Why wrapping a function into a lambda potentially
- Generating powerset in one function, no explicit r
- Check if tie in count of lists using linq
- Trouble with OR in Sharepoint CAML
- C# to VB - How do I convert this anonymous method
相关文章
- 想问问Linq中有没有根据条件选择要不要关联表。
- Why doesn't C11 support lambda functions
- Why do I need a ToList() to avoid disposed context
- LINQ .Include() properties from sub-types in TPH i
- Can a method chain be called LINQ?
- Get grouped comma separated values with linq
- How does a LINQ expression know that Where() comes
-
Creating dynamic Expression
>
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:This will get you the IDs that are only in list2:
If your objects compare equal when they have the same ID then you can simplify it to: