ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.Data Namespace / TableDefinition Class / GetFields Method
Example

In This Topic
    GetFields Method (TableDefinition)
    In This Topic
    Gets the fields in the Table. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public IReadOnlyList<Field> GetFields()
    Public Function GetFields() As IReadOnlyList(Of Field)

    Return Value

    The collection of fields in the Table.
    Exceptions
    ExceptionDescription
    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);
      }
    }
    Removing fields from a Table
    public void RemoveFieldTableSnippet(Geodatabase geodatabase)
    {
      // Removing all fields from 'Parcels' table except following 
      // Tax_Code
      // Parcel_Address
    
      // The table to remove fields
      string tableName = "Parcels";
    
      TableDefinition tableDefinition = geodatabase.GetDefinition<TableDefinition>(tableName);
      IReadOnlyList<Field> fields = tableDefinition.GetFields();
    
      // Existing fields from 'Parcels' table
      Field taxCodeField = fields.First(f => f.Name.Equals("Tax_Code"));
      Field parcelAddressField = fields.First(f => f.Name.Equals("Parcel_Address"));
    
      FieldDescription taxFieldDescription = new FieldDescription(taxCodeField);
      FieldDescription parcelAddressFieldDescription = new FieldDescription(parcelAddressField);
    
      // Fields to retain in modified table
      List<FieldDescription> fieldsToBeRetained = new List<FieldDescription>()
      {
        taxFieldDescription, parcelAddressFieldDescription
      };
    
      // New description of the 'Parcels' table with the 'Tax_Code' and 'Parcel_Address' fields
      TableDescription modifiedTableDescription = new TableDescription(tableName, fieldsToBeRetained);
    
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
    
      // Remove all fields except the 'Tax_Code' and 'Parcel_Address' fields
      schemaBuilder.Modify(modifiedTableDescription);
      schemaBuilder.Build();
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also