CSharp - Parallel LINQ PLINQ ordering

Introduction

Calling the AsOrdered method tells PLINQ to preserve the order of the results.

Demo

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

class Program/* w  w w .  ja  va 2  s . co m*/
{
    static void Main(string[] args)
    {
          string[] codeNames = {"Python", "Java", "Javascript", "Bash", "C++", "Oracle"};
    
          // Parallel LINQ query
          IEnumerable<string> results = from p in codeNames.AsParallel().AsOrdered()
                    where p.Contains('o')
                    select p;
    
          foreach (string president in results) {
              Console.WriteLine("Parallel result: {0}", president);
          }
    }
}

Result

Related Topics