LINQ Interview Question #147

What is PLINQ?

Advanced LINQ, Practical Problems & Senior Interview Scenarios Senior Advanced

Quick Interview Answer

PLINQ is Parallel LINQ, a parallel implementation for LINQ-to-Objects workloads. AsParallel can allow suitable CPU-bound operations to use multiple threads or cores.

Detailed Explanation

PLINQ is Parallel LINQ, a parallel implementation for LINQ-to-Objects workloads. AsParallel can allow suitable CPU-bound operations to use multiple threads or cores.

PLINQ is not automatically faster. Parallelization adds coordination overhead and can affect ordering. It should be used only after measuring a workload that is sufficiently expensive and safely parallelizable.

Code Example

var result = numbers
    .AsParallel()
    .Where(n => ExpensiveCheck(n))
    .Select(n => Transform(n))
    .ToList();