C# Yield Return: What is it and how does it work?
In this video, I explain what the yield return in C# is, how yield return works, and when you would use yield return.
When you use the yield return statement in your code, you indicate that the method, operator, or get accessor in which the yield return keyword appears is an iterator.
You use yield return statement to return one one element in a collection at a time.
The result returned from a yield return iterator method can be consumed by using a foreach statement or LINQ query. Each iteration of the foreach loop calls the iterator method. When a yield return statement is reached in the iterator method, the result is returned and the current location in the iterator method is retained. Upon the execution of the next element in the foreach loop, the iterator method is restarted from the retained location the next time that the iterator method is called.
Essentially, using the yield return statement turns a method into a custom iterator.
GitHub link; https://github.com/brianlagunas/YieldReturn
Be sure to watch my new Pluralsight course "Introduction to Prism for WPF":
📺 http://bit.ly/PrismForWpf
Sponsor Me on GitHub:
🙏🏼 http://bit.ly/SponsorBrianOnGitHub
Get 2 Free Stocks on WeBull (Valued up to $1600 when you deposit $100)
💰 http://bit.ly/BrianWeBull
Follow Me:
🐦 Twitter: http://bit.ly/BrianLagunasOnTwitter
📖 Blog: http://bit.ly/BrianLagunasBlog
Видео C# Yield Return: What is it and how does it work? канала Brian Lagunas
When you use the yield return statement in your code, you indicate that the method, operator, or get accessor in which the yield return keyword appears is an iterator.
You use yield return statement to return one one element in a collection at a time.
The result returned from a yield return iterator method can be consumed by using a foreach statement or LINQ query. Each iteration of the foreach loop calls the iterator method. When a yield return statement is reached in the iterator method, the result is returned and the current location in the iterator method is retained. Upon the execution of the next element in the foreach loop, the iterator method is restarted from the retained location the next time that the iterator method is called.
Essentially, using the yield return statement turns a method into a custom iterator.
GitHub link; https://github.com/brianlagunas/YieldReturn
Be sure to watch my new Pluralsight course "Introduction to Prism for WPF":
📺 http://bit.ly/PrismForWpf
Sponsor Me on GitHub:
🙏🏼 http://bit.ly/SponsorBrianOnGitHub
Get 2 Free Stocks on WeBull (Valued up to $1600 when you deposit $100)
💰 http://bit.ly/BrianWeBull
Follow Me:
🐦 Twitter: http://bit.ly/BrianLagunasOnTwitter
📖 Blog: http://bit.ly/BrianLagunasBlog
Видео C# Yield Return: What is it and how does it work? канала Brian Lagunas
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
C# Async Yield Return: IAsyncEnumerable will change your life!!!Intro to Yield in C# - What it is, how to use it, and when it is usefulTask vs ValueTask: When Should I use ValueTask?c# (Csharp):- What is the use of Yield keyword in c# ?Enumerables (IEnumerable, IEnumerator) | C# Programming Tutorials Beginners: 17How do computers read code?Why is async void bad and how do I await a Task in an object constructor in C#?What is an API?Inside a Google data centerWhich do I use, ConfigureAwait True or False?What are ASYNC and AWAIT in C#? Asynchronous Programming TutorialHow to write clean validation clauses in .NETTips For Using Async/Await in JavaScriptDependency Injection ExplainedIs Parallel.For/ForEach in C# actually worth it? (and how to modernize it)How to Cancel Tasks in C# - Using CancellationTokenSource and CancellationTokenThe evolution of Pattern Matching in C# (from version 6 to 10)So You Think You Know C#?How Long Does It Take to Learn Python? (And Get a Job)