CSharp - AsEnumerable for PLINQ

Introduction

The AsEnumerable operator converts a ParallelQuery<T> into an IEnumerable<T> and so forces sequential query execution.

Prototypes

public static IEnumerable<T> AsSequential<T>(
    this ParallelQuery<T> source
)

Demo

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

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