I'm trying to implement a search function, and I want to select all elements that are common in variable A
and B
and remove the rest.
My code looks like this:
A.ForEach(y =>
{
temp = temp.Where(x => x.Id== y.Id);
});
The problem is if A
has some values that temp
doesn't contain, I'll get an empty temp.
I hope I'm clear enough, but just to make sure:
If A
contains 6, 10 and
temp
contains 10, 7. I want to just have 10.
What's correct join or any other Linq statement for this? I'm not able to use intersect
since two variables are from different tables.