Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop through array in linq query

Tags:

c#

linq

Hi all I have a query using Linq that returns a set of records, one of which is the country id, I also have an array of desired countries. Is there a way of either looping through the countries array and seeing if the id is in the results, i want to do something like this

results = from r in results 
where
//jump to my c# array
for(int x = 0;x < array.count; x++)
{
r.countryId.ToString().Contains(array[x]) 
}
select r

thanks

like image 879
andrew slaughter Avatar asked May 11 '26 09:05

andrew slaughter


1 Answers

Try this

var list  =  from r in results
             where array.Contains(r.countryId.ToString()) 
             select r;
like image 108
Yograj Gupta Avatar answered May 13 '26 22:05

Yograj Gupta