Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subtract a generic list from another

Tags:

c#

linq

I am trying remove a list of firmIDs from one list from another. I don't really understand linq but I am pretty sure I need to use it.

List<Firm> firms = GetBusinessDevelopmentFirms(database); List<Firm> trackedFirms = GetAllCLIFirmsBeingTrackedByUser();  var result = firms.Contains(i => trackedFirms.Contains(i.FirmID)); 

The last line doesn't work and the system says "unknown method Contains(?)" even though I have put "using System.Linq;" At the top of the class.

My idea was to remove a list of tracked firms from a list of all firms to find the untracked firms.

I hope this makes sense.

like image 584
Bobby Avatar asked Sep 19 '13 13:09

Bobby


1 Answers

var result = firms.Except(trackedFirms); // returns all the firms except those in trackedFirms 
like image 107
Alireza Avatar answered Sep 22 '22 08:09

Alireza