Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select items from List A where the property is not in List B

Tags:

c#

linq

I have a List<Broadcast> and the Broadcast object has a property called Guid. Now I need to find all Broadcast objects in that list whose Guid property is not an item in List<Guid>. I've found a solution with Except(); but it's not working for me.

Broadcasts.Where(x => x.Guid).Except(readBroadcasts);

What am I doing wrong?

like image 372
Stefan Schmid Avatar asked Jan 28 '26 05:01

Stefan Schmid


1 Answers

Here is a way you can do it :

List<Guid> excludeGuid = ..... // You init guids you want to exclude
List<Broadcast> result = Broadcasts.Where(x => !excludeGuid.Contains(x.Guid)).ToList() ; 
like image 66
Perfect28 Avatar answered Jan 29 '26 20:01

Perfect28