ArcGIS Pro 2.8 API Reference Guide
Search(QueryFilter,TimeRange,RangeExtent,CIMFloorFilterSettings) Method
Example 

ArcGIS.Desktop.Mapping Namespace > BasicFeatureLayer Class > Search Method : Search(QueryFilter,TimeRange,RangeExtent,CIMFloorFilterSettings) Method
A query filter or spatial filter to perform spatial search.
A time filter only works if the layer is time enabled.
A range filter only works if the layer is range enabled.
A floor filter filter only works if the layer has a defined floor field.
Executes a spatial or attribute query to the underlying data source and returns features matching the search criteria. For stream layer, you should call ArcGIS.Core.Data.Realtime.RealtimeFeatureClass.StopStreaming for predictable result. This method must be called on the MCT. Use QueuedTask.Run.
Syntax

Parameters

queryFilter
A query filter or spatial filter to perform spatial search.
time
A time filter only works if the layer is time enabled.
range
A range filter only works if the layer is range enabled.
floor
A floor filter filter only works if the layer has a defined floor field.

Return Value

A RowCursor (you can cast it to FeatureCursor) allows access to the matched features.
Exceptions
ExceptionDescription
This method or property must be called within the lambda passed to QueuedTask.Run.
A geodatabase-related exception has occurred.
Remarks

If there is a definition query set on the feature layer, the Search() method will automatically work on the subset of features in the feature layer that meet the definition criteria. You specify an additional query that will be applied after the feature layer's definition query by passing valid QueryFilter object for the QueryFilter parameter.
If the feature layer has any joins, this Search() method takes that into account.
You can use the cursor returned by Search to update features.

To ensure maximum robustness, callers should explicitly dispose of the returned ArcGIS.Core.Data.RowCursor in either a using statement or a finally block.

For stream layers, especially with high velocity real-time updates, features might get expired (removed) while you are looping through feature cursor.

Example
Querying a feature layer.
var count = await QueuedTask.Run(() =>
{
  QueryFilter qf = new QueryFilter()
  {
    WhereClause = "Class = 'city'"
  };

        //Getting the first selected feature layer of the map view
        var flyr = (FeatureLayer)MapView.Active.GetSelectedLayers()
                          .OfType<FeatureLayer>().FirstOrDefault();
  using (RowCursor rows = flyr.Search(qf)) //execute
        {
          //Looping through to count
          int i = 0;
    while (rows.MoveNext()) i++;

    return i;
  }
});
MessageBox.Show(String.Format(
   "Total features that matched the search criteria: {0}", count));
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

BasicFeatureLayer Class
BasicFeatureLayer Members
Overload List