0

I have Ienumerable<int> Temp1; from DB

and other List<entity> Temp2; with properties Id and name.

I want to compare Temp1 & Temp2(Id) and find the matching Values and have it in a List.

What is the best way to implement this ?

Thanks

4

2 回答 2

6

使用SelectIntersect

var sameIds = Temp2.Select(x=>x.Id).Intersect(Temp1);

首先只选择新的 ID,IEnumerable<int>然后将其与当前可用的相交IEnumerable<int>将为您提供匹配的 ID

于 2013-11-14T10:21:02.717 回答
0
var outp = (from temp1 in Temp1
            join temp2 in Temp2
            on temp1 equals temp2.Id
            select temp2).ToArray();

您也可以使用 Let 并使用 ==。

于 2013-11-14T10:36:41.973 回答