I have a list
that contains int
values, I want to use linq expression to return a result where a property equals the list items values. How can I do that?
list<int> x = ...
var o = anotherList.where(s => s.Id == (the list values));
I have a list
that contains int
values, I want to use linq expression to return a result where a property equals the list items values. How can I do that?
list<int> x = ...
var o = anotherList.where(s => s.Id == (the list values));
var o = anotherList.Where(s => list.Contains(s.ID));
I translate "a property equals the list items values" with "anotherList contains this list ID":
An efficient approach is using Join
:
var o = from al in anotherList
join tlId in thelist
on al.Id equals tlId
select al;
You could also use an anonymous method:
var o = anotherList.Where(delegate(someItem s) { return list != null && list.Contains(s.ID); });