CSharp - Parallel LINQ PLINQ ordering


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


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

class Program/*from  w  w  w  .j ava2  s  .com*/
    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);


Related Topics