End Sub. Note: The Select(), OrderBy(), and Where() methods are extension methods off of the IEnumerablegeneric class
Note: The Select(), OrderBy(), and Where() methods are extension methods off of the IEnumerable generic class, however you are accessing them in a static manner here. You will try a more succinct usage later. The ToList() call is for illustrative purposes and is not always necessary in production code. It is used here because you want to immediately fire the LINQ query to collect all of the Employee Info strings, and then write them out to screen later. If you were to leave the ToList() off, the query will still fire in order of the Employee ID but each call to GetEmployeeInfo() wouldn’t fire until the IEnumerable generic is iterated through during the foreach loop. This is known as Delayed Execution. See Scott Wisniewski’s article at http://msdn.microsoft.com/en-us/magazine/cc163378.aspx for more information.
5. Build and run the application. 6. You should observe that the LINQ query performs the operations in order of the Employee ID. Also observe the total amount of time required to complete the work (the exact time required will vary): Figure 13 Output from a non-parallelized LINQ query
7. It is easy to parallelize this query by making use of the static ParallelEnumerable class’s version of the same LINQ methods. Additionally you’ll need to add an AsParallel() call to the query’s data source. Modify the Main() method just to call the PLINQAsParallel method. C# static void Main(string[] args) { ... // Methods to call
|