Click here to Skip to main content
14,665,569 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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

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.
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100