简体   繁体   中英

LINQ get elements from one collection that don't belong to another

我有一个List<MyObject> allObjectsList<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM