c# - Linq statement to select common elements between two collections -
i'm trying implement search function, , want select elements common in variable a , b , remove rest.
my code looks this:
a.foreach(y => { temp = temp.where(x => x.id== y.id); }); the problem if a has values temp doesn't contain, i'll empty temp.
i hope i'm clear enough, make sure: if a contains 6, 10 , temp contains 10, 7. want have 10.
what's correct join or other linq statement this? i'm not able use intersect since 2 variables different tables.
you want use join.
a.join(b, => a.id, b => b.id, (a,b) => new { = a, b = b }); this result in enumerable rows , b joined , anonymous type of:
public class anonymoustype { atype a; btype b; } join information c# joins/where linq , lambda
Comments
Post a Comment