CSharp - PLINQ ForAll method


Used on a ParallelQuery, ForAll performs a System.Action on each item in the sequence.

We can output element using the ForAll method.

We use the Where method to filter the sequence and we print out the names directly using a lambda expression passed to the ForAll method.


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

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

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


Related Topic