简体   繁体   中英

Excluding an item from a list where an element matches an element from another list of a different type

I have the following populated lists:

List<Item> Items
List<long> QueueID

Where Item is this:

public Class Item
{
long QueueID    
....
}

I need to make a new List of Items that excludes Items with QueueIDs that are in the other List.

I'm trying this but the compiler doesn't like it.

var result = Items.Where(x => !QueueID.Exists(x => x.QueueID));

您可以通过List.Contains使用此方法:

List<Item> resultList = Items.Where(x => !QueueID.Contains(x.QueueID)).ToList();

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