ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Core.Data Namespace / Table Class / Sort Method
The TableSortDescription which describes the details of how the table sort operation should be carried out.
Example

In This Topic
    Sort Method
    In This Topic
    Sorts data from this table or feature class. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    tableSortDescription
    The TableSortDescription which describes the details of how the table sort operation should be carried out.

    Return Value

    A RowCursor that holds the sorted Row or Feature.
    Exceptions
    ExceptionDescription
    tableSortDescription is null.
    A geodatabase-related exception has occurred.
    Example
    Sorting a Table
    public RowCursor SortWorldCities(FeatureClass worldCitiesTable)
    {
      using (FeatureClassDefinition featureClassDefinition = worldCitiesTable.GetDefinition())
      {
        Field countryField = featureClassDefinition.GetFields()
          .First(x => x.Name.Equals("COUNTRY_NAME"));
        Field cityNameField = featureClassDefinition.GetFields()
          .First(x => x.Name.Equals("CITY_NAME"));
    
        // Create SortDescription for Country field
        SortDescription countrySortDescription = new SortDescription(countryField);
        countrySortDescription.CaseSensitivity = CaseSensitivity.Insensitive;
        countrySortDescription.SortOrder = SortOrder.Ascending;
    
        // Create SortDescription for City field
        SortDescription citySortDescription = new SortDescription(cityNameField);
        citySortDescription.CaseSensitivity = CaseSensitivity.Insensitive;
        citySortDescription.SortOrder = SortOrder.Ascending;
    
        // Create our TableSortDescription
        TableSortDescription tableSortDescription = new TableSortDescription(
          new List<SortDescription>() { countrySortDescription, citySortDescription });
    
        return worldCitiesTable.Sort(tableSortDescription);
      }
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also