IEnumerable Interface
Defines a method, GetEnumerator, that supports a simple iteration over a non-generic collection. This is the base interface for all non-generic collections in the .NET Framework.
The IEnumerable interface is the non-generic equivalent of IEnumerable<T>. Collections that implement IEnumerable can be iterated over using a foreach loop (in C#) or a For Each loop (in Visual Basic).
Syntax
Remarks
Classes that represent collections of objects should implement the IEnumerable interface. This allows the collection to be iterated over.
The IEnumerable interface has one member: GetEnumerator. This method returns an IEnumerator object, which provides methods to step through the collection.
Members
| Member | Description |
|---|---|
| GetEnumerator | Returns an enumerator that iterates through a collection. |
Methods
| Method | Description |
|---|---|
| IEnumerator GetEnumerator() | Returns an enumerator that iterates through a collection. Return ValueAn IEnumerator object that can be used to iterate through the collection. For collections that implement IEnumerable<T>, this method returns an IEnumerator<T> object. |