Order by (keyword)
From The Oxygene Language Wiki
This is a Language topic
Feel free to add your notes to this topic below.
As an example, we might want to print an alphabetical list of customers, we can write:
var x := from c in MyCustomers order by c.Name; for each cust in x do Console.WriteLine(cust.Name);
This will print the names of all customers from MyCustomers, in alphabetical order.
The expression specified in the order by clause can be any valid Delphi Prism code that returns something comparable (in this case a string). Instead of a simple field, we might have made more complex calculations, or called a method – perhaps using a sophisticated algorithm to evaluate the customer's spending history.
Sort order
The sort order can be adjusted by appending either the asc or desc keyword to the clause, with "asc" being implied by default.
You can also order by multiple fields at the same time, by providing a list of expressions, such as
... order by c.Name asc, c.DateOfBirth desc;
See Also
Area: Oxygene Language
Compiler version: Oxygene 5
Language Glossary — Keywords — Types — FAQ — How To