CSharp - Parallel LINQ ForAll

Introduction

ForAll operator accepts an action that will be performed on each element in the source data sequence.

Prototypes

public static void ForAll<T>(
          this ParallelQuery<T> source,
          Action<T> action
      )

Demo

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

class Program/*from w w  w. ja  v a 2s.  c o  m*/
{
    static void Main(string[] args)
    {
      string[] codeNames = {"Python", "Java", "Javascript", "Bash", "C++", "Oracle"};

      // Parallel LINQ query
      codeNames.AsParallel()
          .Where(p => p.Contains('o'))
          .ForAll(p => Console.WriteLine("Name: {0}", p));
    }
}

Result

Related Topics