liveBook · Manning

IEnumerable<T>

As explained in C# Concurrency: Asynchronous and multithreaded programming

IEnumerable<T> is a .NET generic interface representing an object that can provide an enumerator for traversing a sequence of values.

IEnumerable<T> is the basic .NET interface for values that can be treated as collections or sequences. It exposes an enumerator, whose Current value and MoveNext operation let foreach traverse items without knowing the underlying collection type. section 2.2

Iterator methods using yield return are compiled into enumerable and enumerator implementations. The generated state machine resumes execution at each yield, produces one value, and suspends until the next request. section 2.2

List versus yield return

A method can build a List<int> before returning it, or return IEnumerable<int> with yield return 1 and yield return 2. Both support foreach, while the iterator form supplies values incrementally through the generated enumerator.

How C# Concurrency: Asynchronous and multithreaded programming covers it

How deep it goes
Explains the interface contract and compiler-generated iterator state machine, stopping short of broader collection implementation details.
Examples
Compares returning a List<int> with yielding integers through an iterator method.
What you can do after
Apply it via foreach and understand how yield return becomes an enumerator-driven implementation.
How it connects
Connects IEnumerable<T> with IEnumerator<T>, foreach, generic collections, and yield return.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of C# Concurrency: Asynchronous and multithreaded programming. The section links point to the parts of the book it draws on.