System.Collections.IEnumerable

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

See Also: IEnumerable Members

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.Guid("496B0ABE-CDEE-11d3-88E8-00902754C43A")]
public interface IEnumerable

Remarks

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.

Requirements

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