Official Content

Sorts the elements of an SDT collection variable. It also sorts a variable based on a simple data type that is a collection.

Syntax

&VarBasedOnSDTCollection.Sort("[ColumnListString]")     |     &VarThatIsCollection.Sort()

Where:

ColumnListString
    List of SDT elements to sort in a string separated by a comma. Ascending order is set by default. Use [] or () to set a descending order.

Scope

Generators:  .NET, .NET Framework, Java


Samples

1) Consider the following SDT collection:

SDT_Collection
  SDT_Item
    Id
    Number

And the &VarSDT variable based on the SDT_Collection SDT.

To order ascending by Id:

&VarSDT.Sort("Id")

To order descending by Id:

&VarSDT.Sort("[Id]")

To order ascending by Id and descending by Number:

&SDT_Sort.Sort("Id,[Number]")

To order descending by Id and ascending by Number:

&SDT_Sort.Sort("(Id),Number")

 

2) Consider the &CustomerNameCollection variable based on the Character data type.

To order ascending the collection of customer names:

&CustomerNameCollection.Sort()


Considerations

The C# generators use the method ArrayList.Sort from .NET Framework. It compares two String objects by evaluating the numeric values of the individual Unicode characters of the strings using the CompareOrdinal method.

Java uses the standard:  String API to compare elements; it compares them lexicographically. The comparison is based on the Unicode value of each character in the strings.

All implement the Quicksort algorithm; equal elements do not preserve order.

See Also

Structured Data Type methods
Structured Data Type






Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant