Exposes an enumerator, which supports a simple iteration over a non-generic collection.

See Also: IEnumerable Members


public interface IEnumerable


IEnumerable is the base interface for all non-generic collections that can be enumerated. For the generic version of this interface see IEnumerable`1. IEnumerable contains a single method, IEnumerable.GetEnumerator, which returns an IEnumerator. IEnumerator provides the ability to iterate through the collection by exposing a IEnumerator.Current property and IEnumerator.MoveNext and IEnumerator.Reset methods.

It is a best practice to implement IEnumerable and IEnumerator on your collection classes to enable the foreach (For Each in Visual Basic) syntax, however implementing IEnumerable is not required. If your collection does not implement IEnumerable, you must still follow the iterator pattern to support this syntax by providing a GetEnumerator method that returns an interface, class or struct. When using Visual Basic, you must provide an IEnumerator implementation, which is returned by GetEnumerator. When developing with C# you must provide a class that contains a Current property, and MoveNext and Reset methods as described by IEnumerator, but the class does not have to implement IEnumerator.


Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0,,