I'm still very new to LINQ and PLINQ. I generally just use loops and List.BinarySearch
in a lot of cases, but I'm trying to get out of that mindset where I can.
public class Staff
{
// ...
public bool Matches(string searchString)
{
// ...
}
}
Using "normal" LINQ - sorry, I'm unfamiliar with the terminology - I can do the following:
var matchedStaff = from s
in allStaff
where s.Matches(searchString)
select s;
But I'd like to do this in parallel:
var matchedStaff = allStaff.AsParallel().Select(s => s.Matches(searchString));
When I check the type of matchedStaff
, it's a list of bool
s, which isn't what I want.
First of all, what am I doing wrong here, and secondly, how do I return a List<Staff>
from this query?
public List<Staff> Search(string searchString)
{
return allStaff.AsParallel().Select(/* something */).AsEnumerable();
}
returns IEnumerable<type>
, not List<type>
.
from s in allStaff.AsParallel() where s.Matches(searchString) select s
. – Candler