- IEnumerator is an interface from the Systems.Collection namespace which provides the infrastructure to allow the caller to iterate over the internals of the implementing type.
- It provides methods MoveNext() and Reset() and a property Current which all help in iterating through the non-generic collection that implements Enumerator.
- an instance of type IEnumerator is provided by the GetEnumerator() method which is present in the IEnumerable interface.
- The IEnumerable interface enables the implementing type to be iterated by providing an appropriate Enumerator instance of it.
- A type can be used over a foreach loop only if it implements an IEnumerable (which supplies the required IEnumerator instance)
What is the difference between IEnumerator and IEnumerable?
- IEnumerator is an interface from the Systems.Collection namespace which provides the infrastructure to allow the caller to iterate over the internals of the implementing type.
- It provides methods MoveNext() and Reset() and a property Current which all help in iterating through the non-generic collection that implements Enumerator.
- an instance of type IEnumerator is provided by the GetEnumerator() method which is present in the IEnumerable interface.
- The IEnumerable interface enables the implementing type to be iterated by providing an appropriate Enumerator instance of it.
- A type can be used over a foreach loop only if it implements an IEnumerable (which supplies the required IEnumerator instance)