c# (Csharp):- What is the use of Yield keyword in c# ?

Поділитися
Вставка
  • Опубліковано 29 вер 2024
  • For more such videos visit www.questpond.com
    For more such videos subscribe www.youtube.co...
    See our other Step by Step video series below :-
    Learn C# Step by Step goo.gl/FNlqn3
    Learn Design Pattern Step by Step:- goo.gl/eJdn0m
    Learn Angular tutorial step by step tinyurl.com/yc...
    Learn MVC Core step by step :- tinyurl.com/y9j...
    Learn Azure Step by Step :- tinyurl.com/y6...
    Learn SharePoint Step by Step in 8 hours:- goo.gl/XQKHeP
    Python Tutorial for Beginners:- • Python Tutorial for Be...
    Learn Data Science in 1 hour :- tinyurl.com/y5...
    Learn Power BI Step by Step:- tinyurl.com/y6...
    Learn MSBI Step by Step in 32 hours:- goo.gl/TTpFZN
    Learn SQL Server Step by Step tinyurl.com/ja4...
    Learn Tableau step by step :- tinyurl.com/kh...
    In this video we will try to understand what is the use of Yield keyword. Yield keyword helps us to do custom stateful iteration over .NET collections. In this video we will understand the same with a full demonstration.
    We are also distributing a 200 page Ebook ".NET Interview Question and Answers". If you want this ebook please share this video in your facebook/twitter/linkedin account and email us on
    questpond@questpond.com with the shared link and we will email you the PDF.

КОМЕНТАРІ • 188

  • @dnfvideo
    @dnfvideo  3 роки тому

    Do not miss our Interview Question video series
    30 Important C# Interview Questions : ua-cam.com/video/BKynEBPqiIM/v-deo.html
    25 Important ASP.NET Interview Questions : ua-cam.com/video/pXmMdmJUC0g/v-deo.html
    25 Angular Interview Questions : ua-cam.com/video/-jeoyDJDsSM/v-deo.html
    5 MSBI Interview Questions : ua-cam.com/video/5E815aXAwYQ/v-deo.html

  • @Stakkeroid
    @Stakkeroid 4 роки тому +26

    Found this clip via Stack Overflow and wow I finally understand Yield clearly and intuitively. What a great video, thank you!

  • @Theorchero
    @Theorchero Рік тому

    9 years later and this really helped me understand. Thanks man, found you via Stack overflow.

  • @ahlamh8070
    @ahlamh8070 3 роки тому

    Thank you sir, this really clarified my confusion.

  • @KevTheImpaler
    @KevTheImpaler 9 років тому +2

    Thank you for taking the trouble to explain to explain this feature.

  • @RockoShaw
    @RockoShaw 6 років тому

    Excelent explanation, thank you!

  • @MikeStock88
    @MikeStock88 2 роки тому

    Great explanation

  • @teamofsteve
    @teamofsteve Рік тому

    How can you understand the explain the use of Yield and not learn the correct way to pronounce the word yield?

  • @DeeArr
    @DeeArr 8 років тому +34

    yee - eel-d, not eeld.

    • @miracaknar9549
      @miracaknar9549 8 років тому

      +DeeArr Thank you!

    • @nathanunderbsd5972
      @nathanunderbsd5972 5 років тому

      wow, now i know how to pronounce it after 3 years...it suppose to be eel(fish) keyword ... shame.

  • @AlexS-gn9tq
    @AlexS-gn9tq 3 роки тому

    The most hated C# feature ever. It's hard to understand and it's used only once every few years - at a job interview.

  • @madjayhawk
    @madjayhawk 8 років тому +52

    You are master teacher. Very very clear. Thank you for taking the time to fully explain this concept.

  • @phongchau1013
    @phongchau1013 8 років тому +18

    You're awesome. This is one of the few concepts in c# where I always had trouble with. Not any longer with this tutorial. Thank you. Btw, with out should be without, one word.

  • @CuriousKaviCruiser
    @CuriousKaviCruiser 10 років тому +5

    The moment I see the yellow screen in the youtube thumbnail, I watch that video without fail because I know its going to be well worth it.. You are doing an awesome job.. Keep it up

  • @vixsharma
    @vixsharma 10 років тому +5

    Can't we do both scenarios without the "Yield" keyword as shown below:
    Scenario 1: static void Main()
    {
    FillList();
    foreach(int i in mylist )
    {
    if (i > 3)
    {
    Console.WriteLine(i);
    }
    }
    Console.ReadLine();
    }
    Scenario 2: static void Main()
    {
    FillList();
    int runningsum = 0;
    foreach(int i in mylist )
    {
    runningsum += i;
    Console.WriteLine(runningsum);
    }
    Console.ReadLine();
    }
    I know i am missing something regarding actual need of 'Yield' here.
    Can someone help please.

    • @bklynmarine91
      @bklynmarine91 10 років тому +1

      thinking the exact same thing.

    • @rosavey
      @rosavey 10 років тому

      With a lot of keywords I don't understand in which scenario's I would use them. But there are always a few scenario's to solve some things/problems. This scenario is maybe not the best way to use the yield keyword, but the first scenario with greater than 3 I thought it really helps me understand the yield keyword. So maybe when I want to make a temp list I remember this video and try it without a temp list and use the yield keyword :)

    • @karthikkeyanv
      @karthikkeyanv 9 років тому +1

      What we can do with YIELD keyword, we can do it without as well.
      But, YIELD just makes it simple and readable.
      Like, what is the C programming can't do that C# does.
      C# just makes coding simple.
      YIELD is like that.
      Thanks.

    • @djomlastic
      @djomlastic 8 років тому +9

      +vikas sharma Well, what you're missing - it's not the point to write to the Console. Take your Scenario 1, and imagine that you need to return that IEnumerable (collection containing numbers 4 and 5) to some other method. If that was the case, you would have to instantiate new collection, fill it with those values, and return it. Two important things here: you have to finish your iteration before you return, and your other method has to wait until you finish. Now, if what you're doing per iteration is not just adding an int to a collection, but some "more expensive" data processing, the method waiting for that data would have to wait for all the "long lasting" iterations to finish. When using "yield", as soon as one iteration is complete, your other method gets the result, and you might decide to break at some point and not even do all the expensive iterations.

    • @muhammadasad924
      @muhammadasad924 8 років тому +1

      +djomlastic Nice one

  • @DanAshurst
    @DanAshurst 9 років тому +8

    Brilliant video, make this neat little feature of C# very easy to understand. Props for explaining the internals too!

  • @venkir1408
    @venkir1408 9 років тому +6

    I always confused with yield and avoid using it. now I got it and will be using it. thanks for great explanation.
    gentlemen thanks for understanding that English is a foreign language for us and not mother tongue.

  • @challica
    @challica 3 роки тому +3

    This is why I love programing - if you are struggling with something, there are guys on you tube that will explain to you.
    Great video.
    Great community.
    One love.

  • @carlosnavarrete1094
    @carlosnavarrete1094 9 років тому +7

    Excelent explanation. Very concise and informative.

  • @KenzoArts
    @KenzoArts 6 років тому +3

    Your explanations for "yield " keyword are more clear than the ones i saw on stack-overflow.
    Thanks dude.

  • @dengelkemier
    @dengelkemier 4 роки тому +2

    Thank you! I was looking for a C# example that explained yield without a lot of extra noise. I found several, but this example was the one where I finally got it! Awesome!

  • @siddharthshinde4480
    @siddharthshinde4480 8 років тому +2

    You cover in your tutorials very uncommon things which is the best thing about your tutorials !! Its difficult to find explanations on these topics at one place. Thank you so much !!

  • @кирилля-ф9ж
    @кирилля-ф9ж 8 років тому +6

    спасибо от русскоязычныз ( thx from Ukrain ) !!! ))

  • @AndrewSteitz
    @AndrewSteitz 10 років тому +3

    Excellent explanation! Your pronunciation of the word "yield" made it difficult for me to follow at first but I caught on. Thanks!

  • @suisgrand6752
    @suisgrand6752 8 років тому +3

    Thank you soo much for explaining yield in such clear way! well done:)

  • @TheOceanLoader
    @TheOceanLoader 3 роки тому +1

    Great video.15 years and today I finally bothered to look up the yield keyword. Happy days!!!
    It was easy enough to follow.
    The only constructive feedback, if I may, would be to help you develop would be that if you ever intent to work in an English speaking country, it is hard to understand.
    Why does the Indian accent omit the "yee" from the beginning of "yield"? Also - the using the singular for "iteration" when you mean the plural "iterations".
    It's only minor but I thought worth mentioning because you're clearly a professional.

  • @nabilyousfi9557
    @nabilyousfi9557 8 років тому +3

    Thank you very much for taking the time to explain this.

  • @rovielabutap8068
    @rovielabutap8068 9 років тому +3

    Thank you so much Sir. Very helpful :)

  • @yussufsabih8215
    @yussufsabih8215 9 років тому +4

    Great explanation , thanks

  • @Arthur-cx1cg
    @Arthur-cx1cg 5 місяців тому

    I dint understand a word, coz I dont speak french, but every your move.next() clearly described the intention of change with a great finale at async/await . Amazing knowledge. Will try to step through this in JS and then will do for C#.
    Thank you!

  • @TruptiSatardekar0607
    @TruptiSatardekar0607 3 роки тому +1

    Reading articles didn't help! However your video, diagram and debugging the code really made a difference. Thank you!! :)

  • @THEspindoctor84
    @THEspindoctor84 8 місяців тому

    you should be a professional teacher, this video is extremely clear and helpful! I hope you've made some money from this video. I also found it from a stack overflow post. Final note: it's early 2024 for me right now.

  • @pervezmeah7783
    @pervezmeah7783 День тому

    I have never seen anyone explain so easily as you. Simply superb

  • @minastaros
    @minastaros Рік тому

    It even works when the generator function walks over deeply nested data structures, using recursion, thus, calling itself in potentially several levels and probably foreach-loops. And the receiver just gets one value after the other neatly serialized... That's not _easily_ possible without pre-buffering the results in next_element()-like functions.

  • @captainsalty5688
    @captainsalty5688 3 роки тому

    Psalm 14:1-3
    King James Version
    14 The fool hath said in his heart, There is no God. They are corrupt, they have done abominable works, there is none that doeth good.

  • @hamza-trabelsi
    @hamza-trabelsi 5 років тому

    i didn't finish the video yet , but why not give a convenient example if i wanted to show only numbers above 3 i would just add an IF statement , If( i>3) { Consol.Writeln(i); }

  • @mushfigagayev4396
    @mushfigagayev4396 4 роки тому +1

    Good !

  • @yaroslavpanych2067
    @yaroslavpanych2067 3 роки тому

    Honestly, just show them MSIL code, it answers ALL questions. There is no need to flex your terrible accent on worst ever example.

  • @ishan9815
    @ishan9815 4 роки тому

    Sir, with due respect your explanation about preserving the data is a little confusing.
    If we observe the debugging closely, what 'yield' keyword does here is:
    When we reach the yield keyword in the for-loop, it returns to the caller BUT DOESN'T EXISTS the method and when another iteration comes, the execution resumes to the very next line of the yield return statement, which here is the end curly brace of the loop, so then it again iterates but from the same iteration count as you said in the video earlier, like it is resuming the execution of this method. So the running total variable never gets destroys but gets out of scope for a short period of time and as the execution of the loop resumes, it comes back in the scope with its existing value.
    Great Video sir, now it makes sense to me how CoRoutines work in Unity.
    Thank you

  • @knitinr
    @knitinr 11 років тому +1

    The example on providing a running total is a good example of the yield keyword - it demonstrates the concept of stateful iteration perfectly!

  • @gyanprakashsa
    @gyanprakashsa 10 років тому +2

    now i have clear understanding!! thnks

  • @prabhumk1978
    @prabhumk1978 3 роки тому

    Hi When you have a variable inside Static method, here its runningtotal, its preserved right, what yield does here to make the runningtotal preserved?

  • @DheerajPalagiri
    @DheerajPalagiri 11 років тому

    I dont understand how the method allows with out proper return type. You used innumerable as return type but not returning that. ..may be yeild does the trick. ..need some more research on yeild...

  • @bullsquid42
    @bullsquid42 8 років тому +2

    Great video, thank you :)

  • @DDStudia
    @DDStudia 9 років тому +2

    thanck you for this video

  • @SergeiKjtydghk
    @SergeiKjtydghk 10 років тому +1

    Awesome example, thank you very much for so nice explanation!!! Have a good day!

  • @BashaBill5
    @BashaBill5 6 років тому +1

    I was trying to understand yield today at work. This video helped me out. thanks.

  • @stephenl7998
    @stephenl7998 9 років тому +2

    clearly explained.
    thanks

  • @shaloms1
    @shaloms1 9 років тому +2

    Thanks learned new things

  • @bhoopendrasharma9474
    @bhoopendrasharma9474 4 роки тому

    Thank you Sir for such a superb explanation...

  • @devilkillerz777
    @devilkillerz777 9 років тому +2

    very good tutorial

  • @Chandigarh5911wala
    @Chandigarh5911wala Рік тому

    what if i write i>3 directly inside the foreach loop without temp list and yield

  • @keyurshah5203
    @keyurshah5203 9 років тому +2

    Thats simply great ..Thanks..

  • @fahmifarhat7076
    @fahmifarhat7076 Рік тому

    Thanks a lot. Your explanation is very clear.

  • @ahmadibdah4592
    @ahmadibdah4592 8 років тому +1

    Thank you so much Sir. Very helpful :)

  • @norfsk
    @norfsk 8 років тому +1

    Thank you for these clear and concise explanations.

  • @VaclavElias
    @VaclavElias 10 років тому +1

    Thanks, finally I am understanding yield! :)

  • @ruchinvincent4884
    @ruchinvincent4884 10 років тому

    Please correct my below understanding too.
    Return : takes control back to caller function for ever providing value to it.
    Yield return : takes control back to caller function, finishes the caller function execution and then brings control back to resume the steps below yield keyword

    • @j1shin
      @j1shin 8 років тому

      +Ruchin Vincent Thats right.

    • @manjeetnandal1
      @manjeetnandal1 4 роки тому

      Great understanding bhai!

  • @swastikprince164
    @swastikprince164 4 роки тому

    Great explanation sir, but subtitle is not showing the code

  • @SomeRandomDude2007
    @SomeRandomDude2007 8 років тому +1

    Awsome video.. Its a nice thing to know.

  • @HFamilyDad
    @HFamilyDad 3 роки тому +1

    Thanks - all say "Y" (go on try it!)

  • @ghostbusterz
    @ghostbusterz 10 років тому +1

    Great video, thanks for the clear explanation.

  • @gokulgopinath7373
    @gokulgopinath7373 4 роки тому

    Awesome thing yield. Thank you

  • @buddhikagunasekera5348
    @buddhikagunasekera5348 4 роки тому

    Thanks. very clear explanation.

  • @ibrahimfikry6624
    @ibrahimfikry6624 Рік тому

    ❤thanks for this valuable content

  • @learnstuffz3002
    @learnstuffz3002 2 роки тому

    Thanks, I understand now what is yield

  • @pervezmeah7783
    @pervezmeah7783 9 місяців тому

    at last i understood yield. Thanks a lot

  • @mushfigagayev4396
    @mushfigagayev4396 4 роки тому

    You are really Master! Thank You.

  • @manickamsundaram3653
    @manickamsundaram3653 7 років тому +1

    nice

  • @doumkatekz
    @doumkatekz 8 років тому +1

    Thank you that helps.

  • @pranavb9768
    @pranavb9768 3 роки тому

    Does yield have delegates at the backend?

  • @Rasmusorum
    @Rasmusorum Рік тому

    No, don't thank me! thank YOU

  • @maheswarreddy.madithati
    @maheswarreddy.madithati 10 років тому +1

    thank you so much...

  • @benzeerashraf9730
    @benzeerashraf9730 2 роки тому

    is Linq where query uses yield return?

  • @Ciubix8513
    @Ciubix8513 2 роки тому

    Oh, so yield kinda preserves the function it's in. Interesting, I've been using it for like 5 years with coroutines in Unity and only now I learned what it actually does.

  • @PramodSingh-kc1ne
    @PramodSingh-kc1ne 5 років тому

    very good explaination.

  • @jaydeepvaghasiya8625
    @jaydeepvaghasiya8625 10 років тому +1

    i yield..

  • @pauljovanovic4459
    @pauljovanovic4459 Рік тому

    great explanations sir

  • @ravimakwana389
    @ravimakwana389 6 років тому

    wow this is very useful. Thanks for this concept.

  • @laksithliyanage2416
    @laksithliyanage2416 3 роки тому

    Excellent Explanation!

  • @rabbanishaik2363
    @rabbanishaik2363 4 роки тому

    Very clear thank you

  • @andrewclark7113
    @andrewclark7113 3 роки тому

    Great explanation!!!

  • @juanclopgar97
    @juanclopgar97 6 років тому

    I've a question, you can use the statment yield only when you return an IEnumerable or IEnumerable collection?, and this only works when you use an iterator (foreach)?

  • @factworld4375
    @factworld4375 5 років тому

    Thank you sir ji.

  • @sac13p
    @sac13p 10 років тому

    Awesome explanation with example. Read MSDN 2-3 times but not getting it correctly. thanks.

  • @RohitGTA
    @RohitGTA 4 роки тому

    Amazing explained

  • @sixjac
    @sixjac 5 років тому

    Good video thanks

  • @MrGilband
    @MrGilband Рік тому

    best explanation

  • @prasannabhss
    @prasannabhss 5 років тому

    Hi, for the first example, instead of temporary collection, shall I take the values greater than 3 using linq . Then why I could use yield in that place only. Kindly clarify it.

  • @conaxlearn8566
    @conaxlearn8566 3 роки тому

    Thank you sir.

  • @johnsailor3590
    @johnsailor3590 8 років тому +1

    awsome

  • @Its_Hack
    @Its_Hack 5 років тому

    You can show the implementation of IEnumerable, how it knows the previous step, this step, and the next one, so in other words yield keyword, is hidden from the developer, implementation of IEnumerable, Big like anyway, thank you

  • @dev0_018
    @dev0_018 2 роки тому

    well explained 👍

  • @ycdcherokee
    @ycdcherokee 6 років тому

    yes, clear lesson. but i still don't understand why this is necessary. what is the real benefit of "yield"? why don't you just put an if condition in the foreach loop?

  • @Thomas..Anderson
    @Thomas..Anderson 7 років тому

    Although I very much dislike videos where some programming practice is presented as they are waste of time, hard to follow and very little information is actually given. But, this one is a rare and blistering exception. Great tutorial. Appreciate the effort with additional animation. Thumb up. Sorry I have only one.

  • @mahmoudadel1232
    @mahmoudadel1232 2 роки тому

    very helpful ❤

  • @armanx2
    @armanx2 4 роки тому

    Best Explanation on yield keyword, for many many years i had issue to understand this thing.

  • @JibinMN
    @JibinMN 3 роки тому

    Simply explained I watched some other popular videos about this topic, but none of them are good to me. But this one did the job Now i know the concept of yield and where to use and how to use THANK YOU

  • @honeybadger6388
    @honeybadger6388 5 років тому

    very nice explanation.. but will it not affect the performance ? what is the advantage of using it over other traditional ways ? please consider memory is not a costly thing now a days..

  • @parapadirapa
    @parapadirapa 5 років тому

    Could someone please clarify: Why a static list property? You are calling it on the same class so.. It doesn't change how you invoke it.. I dont get it.

  • @spawankumar
    @spawankumar 7 років тому

    Nicely explained. Rather than going through many sites which do not even mention on what is discussed in the video we can watch the video and save our time. Thanks!