What Is The Difference Between IEnumerable And iEnumerator ?

Forums C#What Is The Difference Between IEnumerable And iEnumerator ?
Staff asked 1 month ago

Difference Between IEnumerable And iEnumerator?

Answers (1)

Add Answer
Staff answered 1 month ago

IEnumerable:

  • It define only one method GetEnumerator() which is an instance method used on several different collection type.
  • It represents an object that can be enumerated.
  • GetEnumerator() method returns another type of interface called IEnumerator interface for that particular collection.

IEnumerator:

  • It defines two method MoveNext() and Rest() and a property current.
  • It is used by foreach statement to iterate through the collection.
  • The Rest() sets the enumerator to its default position and MoveNext() advance the enumerator to the next element.

can please provide a small example over here?

Tabish Rangrej replied 1 month ago

Subscribe

Select Categories