IEnumerable<T> Interface
Summary
Represents a strongly typed collection that can be enumerated. This is the base interface for all generic collections in the .NET Framework.
public interface IEnumerable<out T> : System.Collections.IEnumerable
Implements
Remarks
The IEnumerable<T>
interface is the base interface for all generic collections that can be enumerated. It allows you to iterate through a collection using a foreach
loop in C# or a For Each
loop in Visual Basic.
Collections that implement IEnumerable<T>
provide a way to access each element in the collection sequentially. The GetEnumerator
method is the key to this functionality, returning an IEnumerator<T>
object that can be used to iterate through the collection.
The out
keyword in the generic type parameter T
indicates that the type parameter is covariant. This means that you can use a more general type than the one specified, for example, you could use an IEnumerable<object>
to refer to a sequence of string
objects.
Methods
-
IEnumerator<T> GetEnumerator()Returns an enumerator that iterates through the collection.