John
John

Reputation: 451

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));

Upvotes: 1

Views: 23

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460138

You can use this approach using List.Contains:

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

Upvotes: 2

Related Questions