Click here to Skip to main content
15,911,786 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hi,
how to use an array of values in one query and use those values in the where clause of other query in the same Action method.
Posted
Updated 23-Aug-12 0:39am
v4
Comments
Eduard Keilholz 23-Aug-12 6:53am    
Don't understand why someone voted 1 for this question, I think there's nothing wrong with this question.

1 solution

have you tried to convert the array to a generic list, and use that list in the where clause?

C#
List<int> lst = new List<int>();
lst.Add(1);
lst.Add(2);
lst.Add(3);

var processes = from dtProcs in Process.GetProcesses()
             where (lst.Contains(dtProcs.Id))
             select dtProcs;


This should do the trick.
 
Share this answer
 
Comments
Matt T Heffron 23-Aug-12 14:09pm    
Since arrays implement IEnumerable and IEnumerable<T>, .Contains() can be used on the array directly, without converting to List<T>.
Eduard Keilholz 26-Aug-12 6:17am    
Good call

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900