C# Yield Return: What is it and how does it work?

2024 ж. 8 Мам.
53 051 Рет қаралды

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; github.com/brianlagunas/Yield...
Be sure to watch my new Pluralsight course "Introduction to Prism for WPF":
📺 bit.ly/PrismForWpf
Sponsor Me on GitHub:
🙏🏼 bit.ly/SponsorBrianOnGitHub
Get 2 Free Stocks on WeBull (Valued up to $1600 when you deposit $100)
💰 bit.ly/BrianWeBull
Follow Me:
🐦 Twitter: bit.ly/BrianLagunasOnTwitter
📖 Blog: bit.ly/BrianLagunasBlog

Пікірлер
  • Great explanation. Here is a tip: Never benchmark code that writes in the console. Console writes are extremely expensive and become the single factor that your code performs poorly by orders of magnitude, which ends up completely masking the true execution time. You can have code that executes in 1 picosecond but a single console write can push that to 1ms completely destroying your results.

    @nickchapsas@nickchapsas3 жыл бұрын
    • Good point. Of course this example comes with the "demo code only" disclaimer 😁

      @BrianLagunas@BrianLagunas3 жыл бұрын
    • Unnecessary comment, Nick. The guy is demonstrating yield return, no reason to play a smart ass

      @allanhouston22@allanhouston2211 ай бұрын
    • @@allanhouston22 It was a fair comment, especially for anyone watching this video that is new to programming concepts.

      @jakebradminster709@jakebradminster70911 ай бұрын
    • @@jakebradminster709 eh, no its not

      @allanhouston22@allanhouston2211 ай бұрын
    • ​@@allanhouston22 who

      @duarteribeiro1520@duarteribeiro152010 ай бұрын
  • That is incredibly helpful. The idea of using Yield Return when you are unsure how much data you may be going over is especially helpful.

    @brent8450@brent845018 күн бұрын
  • Great tutorial! I was struggling with wrapping my head around yield return and this cleaned up all my confusion. Keep up the great work!

    @shotgunanarms@shotgunanarms4 ай бұрын
    • Thank you so much

      @BrianLagunas@BrianLagunas3 ай бұрын
  • Thank you Brian for this explanation. Short and exactly in point.

    @radeksendecki9922@radeksendecki99222 жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Thanks Brian. I love the way this video was organized. It made much sense

    @kasozivincent107@kasozivincent1073 жыл бұрын
    • Thanks for watching as always my friend

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • You are a great teacher. Keep it up. Easy, simple, and concise explanation

    @kopilkaiser8991@kopilkaiser8991 Жыл бұрын
    • Thank you so much. You are too kind

      @BrianLagunas@BrianLagunas Жыл бұрын
  • Best tutorial I've found that explains yield, thanks!!!

    @tirrellcotton@tirrellcotton2 жыл бұрын
    • Thank you so much

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Great explanation!!! I remember using these in coroutines in game engines, now I understand how they work.

    @andrewdavid9051@andrewdavid9051 Жыл бұрын
  • for a complete tutorial you should add yield break. Also: you can not yield return from within a try / catch block and if you need to for some reason to return an empty enumeration you can use Enumerable.Empty(); An important point is also to mention that using the same enumeration twice will cause the iteration to be run twice - which can become very expensive. So, if you need to process all members of an enumeration it is usually best to use ToList or ToArray to enforce the full enumeration.

    @nothingisreal6345@nothingisreal6345 Жыл бұрын
  • It was a really brief explanation ever to understand so a complicated programming statement. Thank you so much!

    @sergiigolembiovskyi1365@sergiigolembiovskyi1365 Жыл бұрын
    • Thank you for your kind comment

      @BrianLagunas@BrianLagunas Жыл бұрын
  • Thank you, another great video. I already use yield but it's always worth learning what you don't know!

    @ChrisBoot@ChrisBoot3 жыл бұрын
    • Thank you for watching and your support.

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Great example, nicely explained with the benchmarking too. Thanks!

    @RobUttley@RobUttley3 жыл бұрын
    • Thank you so much

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Oh interesting! So the compiler actually doesn't fire the method until another method acts upon the object that would contain the return from the method. That's super interesting. Thank you google feed for giving me this video!

    @AarPlays@AarPlays3 жыл бұрын
    • Not only that, but you can have code that will run after the yield return statement was hit. It's a really cool feature.

      @BrianLagunas@BrianLagunas3 жыл бұрын
    • @@BrianLagunas How does the compiler jump between these functions?

      @_nitki_@_nitki_3 жыл бұрын
    • Well, the compiler technically creates an enumerator

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Niiice. Seeing what goes behind the scene is making it easier to understand it

    @ahmedhafiz2419@ahmedhafiz2419 Жыл бұрын
  • Great video, excellent, concise explanation. World class!!!

    @Grond73@Grond73 Жыл бұрын
    • Thank you so much

      @BrianLagunas@BrianLagunas Жыл бұрын
  • Thank you, Brian. That was really good explanation!

    @ivannarykin@ivannarykin4 ай бұрын
    • Thank you so much

      @BrianLagunas@BrianLagunas3 ай бұрын
  • Beautifully explained!! Thanks for this video 🙂

    @maitreyeekar7509@maitreyeekar75092 жыл бұрын
    • Thank you so much

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • What a great Video...... Respect

    @Ibrahimnada1995@Ibrahimnada19958 ай бұрын
    • Thank you very much

      @BrianLagunas@BrianLagunas8 ай бұрын
  • Thank you for this explanation!!

    @willac4261@willac42615 ай бұрын
  • best explanation ever seen on youtube.thanks

    @nailalzuhairi2690@nailalzuhairi26902 жыл бұрын
    • Thank you very much

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • thank you for this clear explanation!

    @yuliaazarina6789@yuliaazarina67897 ай бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas6 ай бұрын
  • I knew about yield return earlier but learnt about memory diagnoser and performance comparison... Thanks! 😉

    @ApurvKumar2@ApurvKumar23 жыл бұрын
    • Great! Thanks for watching

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Great video. Another thing that worth mentioning is “yield break” which mean you can iterate on demand but when something happens you can just stop , yield break is simple, when move next is called and yield break called , current value == null

    @eldadmo@eldadmo3 жыл бұрын
    • Great point. I probably should have covered this in my video

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Very clear explanation, thank you!

    @volimax@volimax2 ай бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas2 ай бұрын
  • Thank you so much Brian 🏅

    @saifullahkhan3465@saifullahkhan34652 жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Thank you, Mister Lagunas!

    @user-wp3zs9tj7r@user-wp3zs9tj7r3 жыл бұрын
    • You are very welcome

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Thank you so much, really great explanation!

    @joakimcarlsson7826@joakimcarlsson78263 жыл бұрын
    • Glad you enjoyed it!

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Thank you! it really helped me to get started Csharp!!

    @sdasddsasadad2287@sdasddsasadad22873 жыл бұрын
    • That's great! I'm so glad I could help

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Wow I've learned more from this video than from my own teacher about this subject, worthy of a subscribe and a like;)

    @lennertsoffers3491@lennertsoffers34912 жыл бұрын
    • Thank you so much

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Genius as usual many thanks for ur valuable tutorial

    @solvedplus858@solvedplus8582 жыл бұрын
    • Thank you

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Great explanation Brian. Subscribed!

    @davidharrington1133@davidharrington11332 жыл бұрын
    • Thank you very much

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Now I am not afraid of yield :-) Thank you very much.

    @e-cogs@e-cogs2 жыл бұрын
    • Thanks for watching. I'm glad I could help

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Thanks for this. I just watched a course on Linq on Pluralsight yesterday and for those that don't know this is how some Linq operators work as well. For example if you use Where(x => x.Age==32).Take(5) it will not have to loop the entire collection, just until it finds 5 matches.

    @erik....@erik....3 жыл бұрын
    • That's correct. Thanks for sharing

      @BrianLagunas@BrianLagunas3 жыл бұрын
    • Which course was that if you still remember? I watched one on there on that topic but it wasn't that in-depth. Cheers!

      @WilcoBrouwer@WilcoBrouwer2 жыл бұрын
  • Nice explanation, thanks for sharing

    @danielvillalba4457@danielvillalba44572 жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • This is fantastic, thanks so much Brian :-) I think a crash course on Asynchronous programming by you would be amazing. Is this too broad?

    @jkahlon101@jkahlon1013 жыл бұрын
    • Thanks for watching. That would be pretty broad, but when I get some time I'll think about what that may look like.

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • what an easy explanation... thanks...

    @AmmarTheTrainer@AmmarTheTrainer2 жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Thanks so well explained.

    @rodeaglerod2715@rodeaglerod27152 жыл бұрын
    • Thank you so much

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Thank you so much for sharing this knowledge!! you are very kind! Have a nice day:)

    @deckermv7530@deckermv75302 жыл бұрын
    • Thank you very much

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • thank you ...Great explanation.. i understand concept

    @mukundmagdum4897@mukundmagdum489710 ай бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas10 ай бұрын
  • So it's basically syntactic sugar for writing a lazy enumerator, in the sense that it lazily evaluates the code needed to push the iterator the to the next position (to actually produce the data on that next pos) and this lazy evaluation causes the code jumps we see while debugging and also permits the enumerator to consume less memory in the enumerator setup phase. But as others more "in tune with the compiler" have pointed out on Twitter, and other places, yield return is more costly in terms of OP speed when you run it all the way, just because of these jumps. With very large collections and big batches of work, the difference can become significant. I think yield return is very rarely used in practice.

    @PaulSebastianM@PaulSebastianM2 жыл бұрын
    • Exactly, it is syntactical sugar. I think anytime we talk about a “significant” perf difference, it needs to be measured and compared. Often I see these perf concerns turn out to be nothing of concern.

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • rock solid explanation

    @Klosra@Klosra Жыл бұрын
    • Thank you very much

      @BrianLagunas@BrianLagunas Жыл бұрын
  • Спасибо за объяснение)

    @mikhail7658@mikhail76582 жыл бұрын
  • Doing the lord‘s work there.

    @mandivambajavangwe5923@mandivambajavangwe59233 жыл бұрын
    • LOL... that's funny

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Very helpful. Thank you!

    @codyeversole8416@codyeversole84163 жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Wow, amazing tutorial.

    @onlyrock1351@onlyrock13512 жыл бұрын
    • Thank you! Cheers!

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Hello Brian, How much time do you spend to plan such a video? Your explanations are as always on point! Always a pleasure to watch it, no matter if I know it or not.

    @MrJPhardy@MrJPhardy3 жыл бұрын
    • Depends on the topic. Usually it takes a day to create the demos, record, edit, and publish a video. Thanks for watching

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Great video! I'd like a video about benchmarking

    @fullemptiness@fullemptiness3 жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Thanx Brian.

    @neilvermeulen5283@neilvermeulen5283 Жыл бұрын
    • Thank you for watching

      @BrianLagunas@BrianLagunas Жыл бұрын
  • thanks brother from another mother mr

    @henrik3098@henrik30986 ай бұрын
    • Thank you for watching

      @BrianLagunas@BrianLagunas6 ай бұрын
  • Great tutorial, completely understood. Thanks ! (Completed 700 likes)

    @ajaysonar662@ajaysonar6622 жыл бұрын
    • Thank you so much!

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Brian, thanks for your videos! Could you please explain what Covariance and Contravariance in simple?

    @user-uj9mj5qu5f@user-uj9mj5qu5f8 ай бұрын
  • wow , very informative thanks

    @scotolivera8207@scotolivera82072 жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Thanks, this video very userful

    @haule5844@haule58443 жыл бұрын
    • Thank you for watching

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • So helpful!

    @hussainhussaini2267@hussainhussaini22673 жыл бұрын
    • I'm so glad

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • What a great channel 🤩

    @marcotaliente4785@marcotaliente47852 ай бұрын
    • Thank you!

      @BrianLagunas@BrianLagunas2 ай бұрын
  • Enumerators and Iterators! very interesting.

    @BahawalTV@BahawalTV2 жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Thanks for the video, quick question if you can answer, can we have normal return and yield return in same method, i mean like having if else statement (in a method) and differnt kinds of reutnrs in them?

    @rock_0075@rock_0075 Жыл бұрын
  • I use yield to process thousands of entities / children entities. For example, My scenes update and draw entities on that current scene. Whenever I add an child entity or non-child entities to a scene, they all get stored there. Children never get stored to the parent for performance reasons. An 1024x1024 (tiles are 16x16) map has over 10,000 entities (if any of those entities have children). It saves a ton of performance and my frames are buttery smooth + fps is a constant 60fps (using vsync).

    @shmelly7275@shmelly7275 Жыл бұрын
    • Wow, thanks an impressive system you’ve built. You should be proud.

      @BrianLagunas@BrianLagunas Жыл бұрын
  • Nice, Thank you, I wonder why the metod GetPeople(1000) doesn't work in the place where it is, but in loop foreach where it doesen' t appear? Maybe compilator has made some optimalisation.

    @krzwyr@krzwyr2 жыл бұрын
  • Very Good!!!

    @arthuran4361@arthuran43612 жыл бұрын
    • Thank you

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Thanks a lot!

    @DevDunkStudio@DevDunkStudio Жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas Жыл бұрын
  • Slight thing on the benchmark part, its a bit misleading to say yield has drastically less time requirements when your case hits the termination logic early. If the termination logic satisfies at the last iteration the time taken would be very similar. Probably applies to memory space too. But yes yield does improve performance a lot on average.

    @HolyRamanRajya@HolyRamanRajya Жыл бұрын
  • Thanks a lot.

    @adamlasry5225@adamlasry52252 жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • bravo!

    @josmit1708@josmit1708Ай бұрын
  • legend

    @sumo479@sumo479 Жыл бұрын
    • Thank you

      @BrianLagunas@BrianLagunas Жыл бұрын
  • Hi Brian thanks for a great explanation. I was wondering if it was possible to utilize the power of yield return when returning an IEnumerable collection encapsulated in a ResponseWrapper object and returned as a IActionResult in the API. You know the response object that has a data collection and pagination and other metadata properties. Is it possible to use this technique or we’re forced to only return IEnumerable type data in which how to return the pagination and other metadata, response headers?

    @evilroxxx@evilroxxx Жыл бұрын
    • You return any object when you yield return.

      @BrianLagunas@BrianLagunas Жыл бұрын
  • Amazing explanation, I do have one question though. In the for loop with the yield, does it create an ienumerator for each return, or is it just one big collection thats being added to then returned to the previous method?

    @tramarthomas6105@tramarthomas6105 Жыл бұрын
    • It’s just a single enumerator that tracks it’s position.

      @BrianLagunas@BrianLagunas Жыл бұрын
    • @@BrianLagunas so if there's a for loop that should iterate 1 million times, but you only allow it to 1000 times, there's only a collection of 1000 objects that was made? Or are those objects thrown out once you're finished with them

      @tramarthomas6105@tramarthomas6105 Жыл бұрын
  • Thank you for the great explanation, Brian! A quick question; you have yield return inside a for loop in "GetPeople" method. If yield return returns on demand, why do we still need that loop? Would a caller not be the one controlling how many objects to return?

    @georget10i@georget10i3 жыл бұрын
    • The method in my example was responsible for creating the Person objects being returned. Keep in mind that yield return must be used to return an IEnumerable. In my example, the caller was controlling how many objects were returned.

      @BrianLagunas@BrianLagunas3 жыл бұрын
    • @@BrianLagunas Exactly! So if the caller was controlling (1000). There is no need for the loop inside the GetPeople method to exist because we control how many objects we want from the "outside", rather than passing an argument with how many we want to generate and return in a list, am I understanding it right?

      @georget10i@georget10i3 жыл бұрын
    • @@georget10i The large loop inside the GetPeople method is simulating a potentially infinite data source. In real use it would be consuming from a stream, file, database, etc. The caller is choosing to consume only the first 1000.

      @strandloper@strandloper3 жыл бұрын
    • @@georget10i Not really. The loop is what is creating each of the 1000 people objects.

      @BrianLagunas@BrianLagunas3 жыл бұрын
    • @@BrianLagunas @Steve Crane Ah, OK, got it, gentlemen. Thank you!

      @georget10i@georget10i3 жыл бұрын
  • Ngl, I really love Java and I am getting into C#, but this is a game changer. Pretty sure you could do something similar in Java, but probably not with Java's default syntax.

    @ismaelfernandezmendez1664@ismaelfernandezmendez16642 ай бұрын
  • as a java developer i find this mindblowing

    @teratoma.@teratoma.2 жыл бұрын
    • It's been over 15 years since I've done any Java. Is it getting any new language features?

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Hey, this was awesome. I was thinking, can you explain how this works with IAsyncEnumerable?

    @WillEhrendreich@WillEhrendreich3 жыл бұрын
    • That is a great suggestion. Since it's new to C# 8, this may be a not-well-known API.

      @BrianLagunas@BrianLagunas3 жыл бұрын
    • Keep an eye out for tomorrow's video 😁

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Brain, is there any library for web like prism , I know about mvvm and mvc , what I am asking about is the modularity concept !

    @MrAmralaa@MrAmralaa3 жыл бұрын
    • Angular has a concept of modules

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Nice explanation. But Visual Studio should have dark color theme.)

    @valixt@valixt Жыл бұрын
    • Heck no. Dark mode is really bad for demos

      @BrianLagunas@BrianLagunas Жыл бұрын
  • great!

    @nithindominic1807@nithindominic18073 ай бұрын
    • Thank you

      @BrianLagunas@BrianLagunas3 ай бұрын
  • So if you don't have direct access to the database and need to stream over an API, how do you get around the http object accumulating all of the records before returning them as one giant list to the client in .Net 6? I've tried using IEnumerable & IAsyncEnumerable along with await foreach, and it always waits for all records at some point in the pipeline before returning. The database may return results one at a time, and the client may render them one at a time, but a result isn't being rendered in the UI as it's being returned from the database. The http object is feeding them to the client one at a time from it's own collection it accumulated from the database.

    @dasfahrer8187@dasfahrer8187 Жыл бұрын
    • Anything over http(s) is a request/response. You can implement paging, or you'll need to use something else like SignalR to push real time updates to the client using long-lived connections

      @BrianLagunas@BrianLagunas Жыл бұрын
  • so if i understand is creating a pool of the necessary number requested than a entire inventory for then to be cut, wich improve in speed and computing.

    @fokozuynen2048@fokozuynen20482 жыл бұрын
    • Yes 😁

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Great

    @abhichohan8837@abhichohan88372 жыл бұрын
    • Thank you

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • "The Lazy Loop" nice name for a roller coaster (or a restaurant, if you serve calamar rings :-))

    @manudelmarche@manudelmarche Жыл бұрын
  • Awesome

    @boukriabdelkhalek6855@boukriabdelkhalek68553 жыл бұрын
    • Thank you

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Is there a yield equivalent for EF. Is AsQuerable() as close as we get with out repeated calls to a database and take? Maybe how does this apply to non- in memory stores? Does it already work with linq?

    @davidwhite2011@davidwhite20113 жыл бұрын
    • LINQ is basically extension methods on IEnumerable and as a method using yield return returns IEnumerable LINQ does work with it. For example in Brian's sample, if GetPeople took no argument and the loop to 1 million was inside it, then GetPeople().Take(1000) would get the first 1000 people.

      @strandloper@strandloper3 жыл бұрын
    • I don't use EF, so I'm not sure about the technical implementation of EF collections. However, @Steve Crane is absolutely correct in his statement.

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Where was the intro? Anyway tech questions are great. Thanks Brian

    @julianturner6203@julianturner62033 жыл бұрын
    • I stopped doing the intro. I didn't see any real value in it. Thanks for your continued support

      @BrianLagunas@BrianLagunas3 жыл бұрын
    • @@BrianLagunas I rolled the intro in my head anyway. The value is to separate the catcher from the content. Maybe you just make a short transition. What so ever, I watch you for the content.

      @julianturner6203@julianturner62033 жыл бұрын
  • Hey Brain, public void RegisterTypes(IContainerRegistry containerRegistry) { containerRegistry.Register("UserServices"); containerRegistry.Register("TestService"); } How prism will create instance for 2 classes. Please post an small video explaining.

    @prabhakaranvelliangiri9655@prabhakaranvelliangiri96552 жыл бұрын
  • Yeah, but if you had to use the list repeatedly, wouldn't it behoove you to create it once and have it handy for multiple uses, even if it did create more elements than necessary in those usages depending on how many times it ends up being needed?

    @user-nw8oi9vn9y@user-nw8oi9vn9y5 ай бұрын
    • I wouldn’t get hung up on the specific example I used to demo the feature. Focus on the functionality of the feature and use it where it makes sense in your apps.

      @BrianLagunas@BrianLagunas5 ай бұрын
  • Next video on Task.continuewith vs await

    @KunalMukherjee3701@KunalMukherjee37013 жыл бұрын
    • Thanks for the suggestion

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • thanks from Russia

    @tomnolane@tomnolane2 жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • GenXers with the death grip on the goatee

    @adamday5045@adamday5045 Жыл бұрын
  • You look like Ismail Baki Tuncer from Turkiye.

    @yavuzerbas875@yavuzerbas875 Жыл бұрын
    • Sounds like a handsome man 😁

      @BrianLagunas@BrianLagunas Жыл бұрын
  • This feels tailor made to asynchronous repository methods where you don't want to use an ORM: start your SqlDataReader, while Read yield return new Class() { PropertiesFromCurrentRow }

    @heuristix77@heuristix774 ай бұрын
  • when using yield return in conjunction with database call to get a bunch of data would it be hitting db every time say a row is returned ?

    @Brombrom41@Brombrom413 жыл бұрын
    • That depends on how you write the code.

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • I wonder how many people click on this thinking it has to do with earning interest on crypto 😂

    @intertubedude@intertubedude3 жыл бұрын
    • Hahahahaha!!! 🤣🤣🤣🤣

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • are you the one who created prism??

    @sreddyj@sreddyj2 жыл бұрын
    • A team created Prism, and I was part of that team. I now own and maintain the project.

      @BrianLagunas@BrianLagunas2 жыл бұрын
  • Hello, first of all big thanks for tutorial, i understand yield is for what but I cant understand why im getting any way 1_000_000 element i have code similar like your. U not showing bottom menus like Locals to understand better about People is have only 1000 element, in my code People showing 1_000_000 element. What is wrong with my code? or which part of this lesson i not understand? namespace CLtest { class Person { public int personID { get; set; } public int personQueue { get; set; } } class MainClass { static void Main() => ProcessPeople(); static void ProcessPeople() { IEnumerable People = GetPeople(1_000_000); foreach(Person p in People) { if (p.personID < 1000) { Console.WriteLine($"ID: {p.personID} | Your queue number: {p.personQueue}"); } else break; } } static IEnumerable GetPeople(int Count) { for(int i = 0; i < Count; i++) { yield return new Person() { personID = i, personQueue = i + 1 }; } } } } screenshot from debugging process of my code in first loop of foreach: i.ibb.co/zV5QBdM/Screenshot-1.png

    @RoyZASTEROiD@RoyZASTEROiD2 жыл бұрын
    • When you expand the People collection while debugging you are forcing the iteration of all items. If you wait to check the collection until after you finish the loop, the collection count should be correct.

      @BrianLagunas@BrianLagunas2 жыл бұрын
    • @@BrianLagunas thanks again for great tutorial

      @RoyZASTEROiD@RoyZASTEROiD2 жыл бұрын
  • I came here to know what that specific thing in the title says. Im a whole 4 minutes in and and I don't understand what yield return is or what it does. That makes incredibly hard to follow along with what you're talking about

    @XZYSquare@XZYSquare3 жыл бұрын
    • I think it's important to understand the problem before talking about how yield return solves it.

      @BrianLagunas@BrianLagunas3 жыл бұрын
    • @@BrianLagunas Yeah but i also dont know what problem im looking for without being able to tell apart what may make yield return great for the situation. I need to know what it is and what it does before i will be able to tell what the example has to do with the concept in the first place. Its like taking a trip to a famous landmark without knowing what to look for. Then when we get home you tell us what makes what we just saw great. I could have been looking at something completely different and so i missed the opportunity of understanding what made it great

      @XZYSquare@XZYSquare3 жыл бұрын
    • Unfortunately, my teaching style isn't for everyone. It seems the way I approach concepts doesn't fit the way you like to learn them. Thats okay. I'm sure there are other videos you can find that may be better suited for what you are expecting to see. I hope they can help you understand better than I could. Thanks for your feedback.

      @BrianLagunas@BrianLagunas3 жыл бұрын
  • Very helpful Video

    @ZiadTorkey@ZiadTorkey Жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas Жыл бұрын
  • Great

    @shahdel-badrawy@shahdel-badrawy Жыл бұрын
    • Thanks for watching

      @BrianLagunas@BrianLagunas Жыл бұрын
KZhead