IEnumerable Interface

System.Collections

Represents a type that is an iterable collection. This is the base interface for all generic and non-generic collection types in the .NET Framework.

Types that implement IEnumerable can be enumerated by a for-each loop (foreach in C#, For Each in Visual Basic). The IEnumerable interface exposes the GetEnumerator method, which returns an IEnumerator object. The IEnumerator object implements the basic enumeration capabilities, such as reading the next element and resetting the enumeration.

Note: For generic collections, prefer using the System.Collections.Generic.IEnumerable<T> interface.

Members

Remarks

The IEnumerable interface is the fundamental interface for enabling collection iteration. It is the base interface for the IEnumerable<T> generic interface.

When you use a for-each loop in C#, the compiler translates the loop into code that uses the IEnumerable and IEnumerator interfaces.

A collection must implement IEnumerable to be enumerated by the for-each loop. This interface allows you to iterate over the elements of a collection without exposing its underlying representation.

See Also