CSharp - Parallel LINQ WithDegreeOfParallelism


The WithDegreeOfParallelism operator sets an upper limit of the number of partitions that will be processed at once by PLINQ.

PLINQ breaks up your source sequence into partitions, which are then processed simultaneously.


public static ParallelQuery<T> WithDegreeOfParallelism<T>(
          this ParallelQuery<T> source,
          int degreeOfParallelism


using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program//  w  w w . j  av a 2 s  .c o  m
    static void Main(string[] args)
          string[] codeNames = {"Python", "Java", "Javascript", "Bash", "C++", "Oracle"};
          IEnumerable<string> results = codeNames
              .Where(p => p.Contains('o'))
              .Select(p => p);
          foreach (string president in results) {
              Console.WriteLine("Match: {0}", president);