This example shows how PLINQ can be used to calculate the even numbers between 1 and 10,000 using multiple threads. Order will be maintained in the resulting list, however keep in mind that AsOrdered
may hurt performance for a large numbers of elements, so un-ordered processing is preferred when possible.
var sequence = Enumerable.Range(1, 10000);
var evenNumbers = sequence.AsParallel()
.AsOrdered()
.Where(x => x % 2 == 0)
.ToList();
// evenNumbers = { 2, 4, 6, 8, ..., 10000 }