Ordering
One of the most commonly used query operations in the world of databases is applying ordering to the elements or records. Obviously, LINQ provides for this, as well:
var memoryHungry = from process in Process.GetProcesses() orderby process.ProcessName, process.WorkingSet64 descending select process;
The preceding query expression translates into the use of two operators, OrderBy
and ThenByDescending
. Their respective roles will become apparent in just a moment:
var memoryHungry = Process.GetProcesses() .OrderBy(process => process.ProcessName) .ThenByDescending(process => process.WorkingSet64);
OrderBy and ...
Get C# 5.0 Unleashed 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.