3

When we search within a feature class, it returns a feature cursor. To get features from a feature cursor, I use following code snippet:

private List<IFeature> GetFeatureList(IFeatureCursor featureCursor)
{
    var features = new List<IFeature>();
    IFeature feature;
    while ((feature = featureCursor.NextFeature()) != null)
        features.Add(feature);
    return features;
}

But problem is for some interfaces and methods, we need this featurecursor. But before passing this feature cursor to that method, I have already traverse it. So, using IFeatureCursor.NextFeature method, I don't get any other feature here. Is there any method or interface or anything that can reset the feature cursor and make the feature cursor re-usable?

2

From the help on ICursor:

Cursors are forward only; they do not support backing up and retrieving rows that have already been retrieved or making multiple passes over data. If an application needs to make multiple passes over the data, the application needs to reexecute the query that returned the cursor.

You really shouldn't be passing around cursors though, IMO. Consider implementing a repository pattern that abstracts the data access layer so instead of passing around a feature cursor, you access the repository which handles the ArcObjects-level code.

See also:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.