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// ww  w.  j  ava  2 s.c  o 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);


Related Topics