Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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:

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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