LINQ Essentials
Here is a regular LINQ query expression. It uses the C# extensions discussed in the previous section. This query returns the list of multithreaded processes that have more than five active threads. For each multithreaded process, the process identifier and process name are returned:
var processes = Process.GetProcesses() .Where(p => p.Threads.Count > 5) .Select(p => new { p.Id, Name = p.ProcessName });
Figure 6-1 diagrams the preceding LINQ query expression. New features of C# 3.0 are mapped to various aspects of the query expression. The processes variable is an implicitly typed variable. The type is defined by the results of the query expression. The Where operator is an extension method. As with any extension method, the first ...
Get Programming Microsoft® Visual C#® 2008: The Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.