我有一个List<MyObject> allObjects
和List<MyObject> someObjects
(所有对象someObjects
属于allObjects
了。我想从要素allObjects
不属于someObjects
?我怎么能做到这一点的LINQ?
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.
var exceptionList= allObjects.Except(someObjects);
尝试这个
allObjects.Except(someObjects)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.