I have a List<MyObject> allObjects and List<MyObject> someObjects (all of the objects in someObjects belongs to allObjects too. I want to get the elements from allObjects which doesn’t belong to someObjects ? How can I achieve that with LINQ ?
I have a List<MyObject> allObjects and List<MyObject> someObjects (all of the objects in someObjects
Share
It’s as easy as
allObjects.Except(someObjects)However, you should be aware that this uses the default equality comparer under the covers to compare the values.
If you wish to use a custom
IEqualityComparer<MyObject>, there’s an overload that allows you to do just that.