Sort the records in the resultset.

Sorting can be done in 3 ways:

  • A sorting expression. This is an easy to use way to sort the recordset on one of more column properties. Sorting can be done ascending and descending.
  • Sorting with a class implementing the generic IComparer<TRecord> interface.
  • Sorting by calling a method with generic Comparison<TRecord> delegate signature.

See the Visual Studio online documentation for an explanation of sorting with the IComparer interface or the Comparer delegate.

The methods are inherited from the RecordsetData class.

public void Sort(string sort_expression)

public void Sort(IComparer<TRecord> comparer)

public void Sort(int index, int count, IComparer<TRecord> comparer)

public void Sort(Comparison<TRecord> comparison)

public void Sort(int index, int count, Comparison<TRecord> comparison)

Sorting with an expression

The expression is a single column name, or a comma-separated list of multiple column names.

To sort in reverse, add the space-separated "desc" or "descending" keyword to the column name.

The sorter supports nested property expressions, such as Name.Length

A null value counts lower than a non-null value. Null comes before anything not null: 1, true, false, "John"

Sort expressions are compiled to comparison functions that, once compiled, are as fast as compile-time generated code.


Sort on Lastname:


Sort on Firstname and Lastname:

customers.Sort("Firstname, Lastname");

Sort on Lastname descending:

customers.Sort("Lastname desc");

Sort on the length of the Name column:



Sorting with an expression uses parts of the Dynamite library, copyright 2008 by Henrik Jonsson. The library is licensed under the Apache License, Version 2.0.