Yield in C#: How to create an iterator with IEnumerable

Опубликовано: 18 Февраль 2025
на канале: Round The Code
858
30

Yield in C# is an underused statement which can be used in an iterator to provide the next value or signal the end of an iteration.

Using the demonstration of odd numbers, we'll show you how to use the yield statement to return an IEnumerable, how to provide the next value using the yield return statement, and how to end an iteration by calling the yield break statement.

As a bonus, we'll also show you how to use yield asynchronously by returning a IAsyncEnumerable type and awaiting for a task to complete.

📖 Learn .NET and C# with our online courses 📖
https://www.roundthecode.com/dotnet-c...

► Chapters
0:00 What is yield?
0:22 View our .NET coding challenges
0:31 Returning items using LINQ
1:18 Yield return
2:04 Yield break
2:47 Yield asynchronously
4:08 View our .NET coding challenges

#yield #csharp