February 2025
Intermediate to advanced
248 pages
6h 36m
English
This chapter covers:
await foreach worksyield return in async methodsIAsyncEnumerable<T> and await foreachSometimes, we may want to use foreach to iterate over a sequence of items we generate on the fly or retrieve from an external source without first adding the entire set of items to a collection. For example, we’ve seen in chapters 8 and 13 how BlockingCollection<T>’s support for foreach makes it easy to use for building a work queue. C# makes this easy with the yield return keyword, as discussed in chapter 2. However, both the versions of yield return we covered in chapter 2 and BlockingCollection<T> don’t support ...
Read now
Unlock full access