Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

c# - Subtract a generic list from another

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
var result = firms.Except(trackedFirms); // returns all the firms except those in trackedFirms

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...