Skip to main content

What is the difference between IEnumerable and IEnumerator?

Junior C#
Quick Answer IEnumerable is the collection รขโ‚ฌโ€ it exposes GetEnumerator() which returns an IEnumerator. IEnumerator is the cursor that walks through items รขโ‚ฌโ€ it has MoveNext(), Current, and Reset(). You implement IEnumerable on your class so it works with foreach. You rarely deal with IEnumerator directly.

Answer

IEnumerable: Represents a collection that can be iterated.

IEnumerator: Performs step-by-step iteration over the collection.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice