Parallel Queries Written Using Query Expressions and Extension Methods
using System; using System.Linq; using System.Collections; using System.Collections.Generic; class Program/*from w w w. java2 s. c o m*/ { static void Main(string[] args) { string[] codeNames = {"Python", "Java", "Javascript", "Bash", "C++", "Oracle"}; IEnumerable<string> results = from p in codeNames.AsParallel() where p.StartsWith("M") select p; foreach (string president in results) { Console.WriteLine("Query expression result: {0}", president); } results = codeNames.AsParallel() .Where(p => p.StartsWith("M")) .Select(p => p); foreach (string president in results) { Console.WriteLine("Extension method result: {0}", president); } } }
The first query is written using query expressions, and the second is written using extension methods.
Both queries call the AsParallel method.