What Is The Difference Between IEnumerable And iEnumerator ?
Answers (1)
Add AnswerIEnumerable:
- 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?