Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

c# - How do I evalutate the set difference between two heterogeneous sets in LINQ?

In (More)LINQ terms how do I do an ExceptBy involving different types?

For example, given the LeverPosting structure defined below, an IEnumerable<LeverPosting>, and an IEnumerable<string>, how do I find all the LeverPostings that "aren't in" the alreadyProcessedIds list?

class LeverPosting
{
    public string Id {get; set;}
}
question from:https://stackoverflow.com/questions/65874635/how-do-i-evalutate-the-set-difference-between-two-heterogeneous-sets-in-linq

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

1 Answer

0 votes
by (71.8m points)

Normally you do something like:

IEnumerable<LeverPosting> postings = ...
IEnumerable<string> idsalreadyProcessedIds = ...

var idsalreadyProcessedIds2 = new HashSet<string>(idsalreadyProcessedIds);

var postings2 = postings.Where(x => !idsalreadyProcessedIds2.Contains(x.Id)));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...