Reputation: 43
I have this array, suppose int[] ageArray=[11,12,13]
And a list with these objects:
public class temp
{
string name;
string age;
}
Now I want to retrieve all items from the list with age
in ageArray
, as size of ageArray
is not known it will be dynamic. Is this possible using List.Select
or List.Where
to query a List using an array.
For Example
List.Select(row=> row.age in ageArray)
this kind of solution?
Upvotes: 0
Views: 1228
Reputation: 882
Try something like
var result = list.Where(x => ageArray.Contains(x.age)).ToList();
Here is a small example: https://dotnetfiddle.net/PyhBst
Upvotes: 6