Index · Quick recall Q&A
1 min readQuick recall Q&A
IEnumerable<T> uses synchronous iteration with yield return and foreach. IAsyncEnumerable<T> supports async operations with await foreach, allowing each MoveNextAsync() to be awaited. Use IAsyncEnumerable<T> when producing items requires I/O or async work.
return exits the method completely. yield return suspends execution, preserving state, and resumes on the next iteration. The method becomes an iterator that produces values lazily.
Use Channels when you need decoupled producers and consumers, multiple producers/consumers, backpressure control, or buffering. Use IAsyncEnumerable<T> for simpler pull-based streaming without complex coordination.
Nothing executes. Iterator methods use deferred execution - code only runs when you iterate (foreach, ToList, etc.). This enables lazy evaluation and early termination.
Use [EnumeratorCancellation] attribute on a CancellationToken parameter. The token is automatically threaded through when using WithCancellation() extension method.