Explain the IEnumerable Interface

Namespace – System.Collections
Assembly mscorlib (in mscorlib.dll)

IEnumerable Interface is the base interface for all non-generic collections that can be enumerated. It exposes an enumerator, which supports a simple iteration over a non-generic collection. System.Collections.Generic.IEnumerable<T> is the generic version of this interface.

IEnumerable contains a single method, GetEnumerator, which returns an IEnumerator which provides the ability to iterate through the collection by exposing a Current property and MoveNext and Reset methods.

Implementation of IEnumerable and IEnumerator on collection classes enables the foreach syntax on a collection. The members of these interfaces are not explicitly called, but they are implemented to support the use of foreach to iterate through the collection.

No comments:

Post a Comment