CSharp - Cast legacy ArrayList to ParallelQuery.

Introduction

We have created a legacy collection that contains some of the codeNames' names.

We then call AsParallel, which returns an instance of ParallelQuery.

We then apply the AsOrdered operator and then so that we have something that we can use with PLINQ.

We call the Cast operator so that we transform our ParallelQuery into a ParallelQuery<string>.

Demo

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

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

Result

Related Topic