What is c# enumerator and enumerable?

An enumerator is a cursor that is read only and moves forward only through a sequence of values.
An enumerator is an object that:
1. Implements IEnumerator
2. Has a method called MoveNext for iterating over the sequence, and a property called Current provides for the reading of the current element of the sequence.

The foreach statement iterates over a enumerable Object. The enumerable object is the logical representation of a sequence and is not itself a cursor.
An enumerable object is an object that:
1. Implements either IEnumerable
2. Has a method called GetEnumerator that returns an enumerator.

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.