Ordering Operators

Ordering operators allow sorting query results according to the given condition. Within LINQ queries, this is accomplished via the Order By clause. This clause allows ordering query results in both ascending and descending order, where ascending is the default. The following example sorts the query result so that products are ordered from the one that has the lowest unit price to the one having the highest unit price:

Dim query = From prod In products            Order By prod.UnitPrice            Select prod

To get a result ordered from the highest value to the lowest, you use the Descending keyword as follows:

Dim queryDescending = From prod In products                    Order ...

Get Visual Basic 2015 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.