C# Yield - Creating Iterators for beginners
Вставка
- Опубліковано 8 лип 2024
- 🔥 Is your code getting stuck iterating? Why not fetch data while it is iterating, avoiding freezes entirely? Well, with YIELD, you can do so!
🚀 C# Progress Academy - Become a job-ready C# and Angular web developer to land your dream developer role: bit.ly/45vbPUg
We'll make sure to turn you into a true developer in no time!
Timestamps:
00:00 Introduction
00:16 What do we need? And why do we want Yield?
01:36 Want to improve your C# Skills?
02:05 Let´s see a problem and build a solution using YIELD Return
05:38 Thanks for watching!
C# yield - creating iterators for beginners
So, what is C#?
C# (pronounced "See Sharp") is a modern, object-oriented, and type-safe programming language. C# enables developers to build many types of secure and robust applications that run in .NET. C# has its roots in the C family of languages and will be immediately familiar to C, C++, Java, and JavaScript programmers. This tour provides an overview of the major components of the language in C# 8 and earlier. If you want to explore the language through interactive examples, try the introduction to C# tutorials.
C# is an object-oriented, component-oriented programming language. C# provides language constructs to directly support these concepts, making C# a natural language in which to create and use software components. Since its origin, C# has added features to support new workloads and emerging software design practices. At its core, C# is an object-oriented language. You define types and their behavior.
And what is the Yield keyword?
You use the yield statement in an iterator to provide the next value from a sequence when iterating the sequence. The yield statement has the two following forms:
yield return: to provide the next value in iteration.
yield break: to explicitly signal the end of iteration.
The return type of iterators is IEnumerable (in non-generic cases, use IEnumerable as the return type of an iterator). You can also use IAsyncEnumerable as the return type of an iterator. That makes an iterator async. Use the await foreach statement to iterate over iterator's result.
To learn more, make sure to watch the video, and we promise you that you'll become a better developer by the end of the video! Have fun!
And thank you LAKEY INSPIRED for these amazing songs that we use in all our videos! @LAKEYINSPIRED
#csharp #coding #tutorial #learn #microsoft #net #yield #optimization
TAGS
c#,.net,c-sharp,csharp,programming,visual studio,c sharp,learn c#,c# programming,c# tutorial,c# for beginners,learn c# programming,c# course,tutorial,coding,c# multithreading,async,thread,multithreading,threading,c# one thread,c# async,core,code,task,async tutorial,asynchronous,shorts,dotnet,yield,ienumerable,yield return vs return c#,yield return,yield statement,yield return statement,iterator pattern c#,c# yield return,yield break,break,return,optimization
TutorialsEU offers you free video tutorials about programming and development for complete beginners up to experienced programmers.
This includes C#, Unity, Python, Android, Kotlin, Machine Learning, etc.
Stay tuned and subscribe to tutorialsEU: goo.gl/rBFh3x
C#: / @tutorialseuc
Facebook: / tutorialseu-1093802040...
LinkedIn: / tutorialseu
Discord: / discord
🚀 C# Progress Academy - Become a job-ready C# and Angular web developer to land your dream developer role: bit.ly/45vbPUg
Definitely a must watch video for every programmer willingful to understand "yield" statement in C#. I myself, have been able to understand thanks to you🎉❤
Nothing wrong with the content. However, this example shows well how much imperative programming interrupts the actual flow of the program and the developer is constantly forced to use control structures. A declarative approach would clearly have an advantage here.
The best explanation
It's really really good, I can understand the "yield" in C# thanks for your video! Nice job!
Is a yield return function setting up an isolated separate thread? That's what it feels like, but I'm having a little bit of trouble holding the logic in my head (which honestly is the case for a lot of multithreading, this would actually be simpler than normal for that.)
⭐️⭐️⭐️⭐️⭐️
but if the max value is large will it not take longer and possibly throw an error
You mean too large for an int
@@hemanichius3941 no I mean if you input a higher value like when he used 1billon will it not still take much time to complete
@@Golden_games Of course it does. Sadly he did not show the console then you would see why yield is very good in this situation. It will print the messages as soon as it iterates through each item because yield provides the next value in the iteration.
Before the change to yield the methode had to finish (IEnumerable) and after that it will iterate through the foreach loop.
Create a app pdfscanned to text file