Using a cursor, this is how I calculated the field "PS_Count" in the FeatureClass "featureClass" to 1.
QueryFilter queryFilter = new() { WhereClause = "1=1" };
EditOperation editOperation = new();
await QueuedTask.Run(() =>
{
using RowCursor rowCursor = featureClass.Search(queryFilter, false);
while (rowCursor.MoveNext())
{
using Row record = rowCursor.Current;
editOperation.Modify(record, "PS_Count", 1);
}
});
if (!await editOperation.ExecuteAsync()) MessageBox.Show(editOperation.ErrorMessage);
The other way you can do this is with the GeoProcessing Tool
IGPResult GPResult = await CalculateFeatures(featureClass, "PS_Count", "1", "ARCADE", null, "LONG", GPExecuteToolFlags.AddToHistory);
if (GPResult.IsFailed)
{
MessageBox.Show("Failed to calculate Count field");
}
public static async Task<IGPResult> CalculateFeatures(FeatureClass InFC, string FieldName, string exp, string exp_type, string code_block, string fieldtype, GPExecuteToolFlags flags)
{
List<object> arguments = new() {
InFC, //In Table
FieldName, //Field
exp, //Expression
exp_type, //Expression Type
code_block, //Code Block,
fieldtype, //Field Type
};
IGPResult result = await Geoprocessing.ExecuteToolAsync("management.CalculateField", Geoprocessing.MakeValueArray(arguments.ToArray()), null, null, null, flags);
return result;
}