c# (Csharp) and .NET :- Difference between IEnumerable and IEnumerator.

Поделиться
HTML-код
  • Опубликовано: 8 фев 2025
  • 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 c# video video we will try to understand in what scenarios we should use IEnumerable and what scenarios we should use IEnumerator.
    We are also distributing a 100 page Ebook ".NET Interview Questions ". 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.

Комментарии • 251

  • @dnfvideo
    @dnfvideo  3 года назад

    Do not miss our Interview Question video series
    30 Important C# Interview Questions : ruclips.net/video/BKynEBPqiIM/видео.html
    25 Important ASP.NET Interview Questions : ruclips.net/video/pXmMdmJUC0g/видео.html
    25 Angular Interview Questions : ruclips.net/video/-jeoyDJDsSM/видео.html
    5 MSBI Interview Questions : ruclips.net/video/5E815aXAwYQ/видео.html

  • @ZhuShisubi
    @ZhuShisubi 11 лет назад +47

    This question has been going around for years and finally someone who just answered it in a very in-depth yet simple way. Thanks from Master Zhu! :)

  • @rajkumararora7366
    @rajkumararora7366 2 года назад +4

    Very well explained in simplistic words.
    This truely signifies the role of a good teacher.
    Shiv sir you are the best !!! Keep it up...

  • @muslimresearcher6062
    @muslimresearcher6062 6 лет назад +6

    I think the more accurate syntax for the difference between IEnumerable and IEnumerator is that: it is not the IEnumerable or IEnumerator maintains the state or not, but the technique of iteration through IEnumerable or IEnumerator rests the position or not.
    As you loop through IEnumerable with foreach loop, the foreach loop automatically resets the IEnumerable position to the initial position each time you iterate.
    While as you iterate through IEnumerator with MoveNext() method the position is maintained
    with the new iteration loop, because nothing automatically changes the position of IEnumerator and if you want the initial position of IEnumerator you must use Reset() method.
    So, the technique used to iterate through IEnumerable rests the position automatically
    each time you iterate, while The technique used to iterate through IEnumerator begins the iteration from the last IEnumerator position and no automatic reset is carried out in IEnumerator iteration.

  • @khurramsultan2040
    @khurramsultan2040 7 лет назад

    i dont know why some stupid people are disliking these videos. this guy has great way of teaching and he is doing it for free and on the other hand he is very well experienced and sharing his experience

  • @kvguitarist
    @kvguitarist 11 лет назад +7

    Also at 10: 16 we should pass int i in the IEnumerable example to 2nd function Iterate2001andAbove() instead of passing o (which is the full list). This will fix listing the years multiple times... :-)
    Hope that helps.. Thank you once again!

    • @MsRohit35
      @MsRohit35 5 лет назад

      Was going to comment the same

  • @AhmadElkhouly
    @AhmadElkhouly 11 месяцев назад

    Thank you. In short, IEnumerable is the collection itself that can be iterated.
    IEnumerator is an enumerator object that's used to iterate through a collection of data.
    So for a collection to be enumerable it must provide an enumerator object. IEnumerable exposes the GetEnumerator method that provides that enumerator.

  • @kvguitarist
    @kvguitarist 11 лет назад +8

    Great video... Would just like to point out one thing... Maybe no one noticed it but at 12:25, you say "The Biggest difference between IEnumerable and IEnumerator is that IEnumerable REMEMBERS STATES while IEnumerable DOES NOT."
    I think you wanted to say "IEnumerator remembers states while IEnumerable does not" Obviously that was an accident. But just wanted to point out. Thank you so much for the help!

  • @tthamil
    @tthamil 10 лет назад

    I was very confused between IEnumerable and IEnumerator before the video, I had a very clear explanations from your videos in depth.Thank You.

  • @RajMalhotra-hf3bv
    @RajMalhotra-hf3bv 4 года назад +1

    Explained very good. Only one small correctionwhere you have said IEnumerable instead of IEnumerator. Statement from Video- " IEnumrable remember state while IEnumerable does not"Look at time 12:20 in video

  • @kopilkaiser8991
    @kopilkaiser8991 2 года назад

    I had these exact questions and you have answered really well with simple and clear explanation. Thank you!

  • @rajendraprasad8814
    @rajendraprasad8814 12 лет назад

    The video was awesome...i was finding it difficult to understand the difference from many sites, this video was crisp and clear...kudos

  • @ssushovan
    @ssushovan 7 лет назад

    You are a life saver. Finally, I get the difference between these two now.

  • @kris4117
    @kris4117 3 года назад

    Now that I understood what I need to.... I am all set for Nirvana - Guru ji with your blessings.

  • @eladyehuda8827
    @eladyehuda8827 3 года назад

    You are a true professional and an excellent explanation

  • @thisistruevine
    @thisistruevine 4 года назад

    Thank your clear explation sir thumbs up from PH🇵🇭

  • @zuzuba3481
    @zuzuba3481 5 лет назад

    Well done. No words to appreciate. Long time confusion is cleared..

  • @jimmynguyen7961
    @jimmynguyen7961 6 лет назад +1

    Love these videos. Very comprehensive explanations.

  • @yaarkhakf
    @yaarkhakf 10 лет назад +155

    now i can die in peace

  • @arun020391
    @arun020391 6 лет назад

    If foreach is the case and we're not interested in current position then why should we choose IEnumerable too instead of we might have use object of List in foreach right and why we go for IEnumerable? can you please anyone clear my doubt, Thank you.

  • @sadaqat4728
    @sadaqat4728 4 года назад

    great work man. hardworking and talented people like you deserve subscribers and appreciation rather than those loser tiktokers.

  • @arunntbe
    @arunntbe 12 лет назад +1

    Really nice video!! you have mentioned that IEnumeratble internally uses IEnumerator, so why it does not remember the current cursor position?

  • @sebastiankumlin9542
    @sebastiankumlin9542 5 лет назад

    Better than most other explanations!

  • @HammadKhanYT
    @HammadKhanYT 3 года назад +1

    There is a bug in this code though not obvious in the tutorial.
    @8:43 In the first function Upto2000, it checks for value weather greater than 200 and then jumps to the second function. But when it jump into the second function o.MoveNext is called and then it print the NEXT value not the current value. So the program is flawed in a sense that the condition check on a value, jump to the second function and then does not uses that value but pull in the next value. It will be more obvious if lets say after 2002, there is a value 1999, it will print in correct value.

  • @THWUFAILUZAMAN
    @THWUFAILUZAMAN 3 года назад +1

    we can use foreach with oyears right? then why you convert oyears to IEnumerable explicity?

    • @mrityunjoysen10
      @mrityunjoysen10 3 года назад

      Yes right, I too thought the same question. Although I think as the video is 9 years old maybe lists were not directly iterable in that version of C#.

  • @mrk10000
    @mrk10000 4 года назад

    You always give excellent examples and analogy, thanks a lot for sharing

  • @LoveShowsNostalgic
    @LoveShowsNostalgic 3 года назад

    Thanks a lots keep posting for us please 🙏👍 ☺️

  • @PVP-learn
    @PVP-learn 5 лет назад +1

    Great explanation ...u reduced my stresssss..

  • @MuhammadYousaf-gd5rs
    @MuhammadYousaf-gd5rs 5 лет назад

    IEnumerator is built for creating your own data types which can be looped through. Its up to you how you implement it.
    You have 1 billion items in a file, if you create a IEnumerable data type to get these items you will be out of memory. But if you implement IEnumerator you can get 1 item at a time and only need 1 item memory to store that value. Then you move next and get next item. It will be very fast and instant for your application to load and loop items.

  • @sushmabaijv4158
    @sushmabaijv4158 11 лет назад +1

    Thank you very much now I got very clear idea about these two interfaces thanks once again

  • @Archak77
    @Archak77 2 года назад

    Excellent explanation sir ...Thank you 🙏

  • @aske1602
    @aske1602 11 лет назад

    Thanks I have been looking for a decent explanation of the difference between the two collections.

  • @phongchau1013
    @phongchau1013 8 лет назад

    Excellent explanation of the difference between the two. Thanks.

  • @idlevandal69
    @idlevandal69 7 лет назад

    Clear and concise explanation.. Awesome..

  • @Rahul999_Official
    @Rahul999_Official 2 года назад

    Very well explained the details.

  • @Nicetrycutiepie
    @Nicetrycutiepie 3 года назад

    Best example I have seen,it's registered in my mind.

  • @henryv4222
    @henryv4222 8 лет назад

    good entertaining explanations- I use it for looping through controls in forms apps but I didn't know what differences between the two were

  • @viranirav
    @viranirav 11 лет назад +1

    Thanks for the video showing the difference between IEnumerable vs IEnumerator. Question, shouldn't we pass int i in the IEnumerable example (when modified at min:11) to 2nd function Iterate2001andAbove instead of passing o (which is the full list). This should fix the results & each year will get listed only once.

    • @Sunstriderko
      @Sunstriderko 2 года назад

      yes that would fix the problem. Anyways, the goal is to show that there might be some cases where you want to pass a whole collection to the next method and do something with it which is more complex than just writing it into console.

  • @mahalakshmip9618
    @mahalakshmip9618 6 лет назад

    Very good Explanation for Enumerator and Enumerable

  • @BigBlue_YT
    @BigBlue_YT 11 лет назад

    Tanks for this show. I learned a lot with video.

  • @dnfvideo
    @dnfvideo  13 лет назад

    Its already uploaded. we would like to clarify to everyone here what videos we upload on youtube are a very very small part what we have on questpondvd.

  • @jitendravirkayade3466
    @jitendravirkayade3466 8 лет назад

    it really help me to understand basic difference, Thanks,

  • @MansoorAman
    @MansoorAman 6 лет назад

    Great video, I think your conclusion may be misleading.
    It's not that the IEnumerable variable is unable to remember its state, it is that you iterate your IEnumerator variable through the data structure using the MoveNext method so that it points at the next element in each iteration through the for loop. The foreach loop used with the IEnumerable is clever enough to understand what you really want to do when you "loop through an IEnumerable"; because it loops through the data structure that the IEnumerable is currently pointing to, start at its current position.

  • @thegr8raj1
    @thegr8raj1 6 лет назад

    Very nice explanation. Thanks for the video.

  • @ashamp1028
    @ashamp1028 11 лет назад

    Very nice and clear explanation... Thanks a lot

  • @bbabak2
    @bbabak2 4 года назад

    Perfect explanation. Thank you

  • @kingwoodbudo
    @kingwoodbudo 6 лет назад

    Thanks for making this much clearer. I appreciate your time.

  • @gen_jain
    @gen_jain 2 года назад

    Wow Sir Awesome ! Nicely explained loved it 😊😊

  • @jamesjackson414
    @jamesjackson414 11 лет назад

    Very good video. As always, well explained, easy to follow code and example. Thanks for sharing with the world.

  • @AmmarTheTrainer
    @AmmarTheTrainer 6 лет назад +3

    at the end we get to know about the main difference between both IEnumerable and IEnumerator . But the question is " why we need all these to implement a loop ?"

    • @monochromenight8943
      @monochromenight8943 6 лет назад +2

      This helped me understand the reasoning:
      programmingwithmosh.com/csharp/ienumerable-and-ienumerator/
      To be able to use loops, the information needs to be exposed, which violates the OOP guideline of information hiding. Implementing the interfaces makes iteration possible without having to make the class's structure public.

    • @pratikgajjar6183
      @pratikgajjar6183 6 лет назад

      @@monochromenight8943 that was really helpful, thanks !

  • @mrsoo9687
    @mrsoo9687 8 лет назад +1

    i love your explanation! thank you so much! you saved me!

  • @paulvincent9473
    @paulvincent9473 3 года назад

    Very good explanation

  • @ISHANICUTIEPIE
    @ISHANICUTIEPIE 2 года назад

    Superb explanation

  • @LOGIGON
    @LOGIGON 11 лет назад

    Thanks, you made the Difference clear!

  • @highlightspoint6182
    @highlightspoint6182 8 лет назад

    excellent lecture clear view

  • @vinaykrishnasharma5024
    @vinaykrishnasharma5024 9 лет назад +5

    Cleared a very important concept. Thanks a lot.

  • @sudhid8765
    @sudhid8765 3 года назад

    Super shiv sir thanks for making my learning easy. I got one doubt to make the ienumerable remember cursor position can we use getenumerator()?

  • @nikolaypanchev
    @nikolaypanchev 9 лет назад

    Simple and clear explained. Thank You!

  • @ASP4U
    @ASP4U 4 года назад

    Please try to make video on MVC Layout. which should not refresh entire layout for each request

  • @sahilchugh6482
    @sahilchugh6482 7 лет назад

    u r superb sir.. Keep helping us

  • @rajasekharjangam4999
    @rajasekharjangam4999 4 года назад

    Super explanation bro..

  • @saranjeetkaur5184
    @saranjeetkaur5184 7 лет назад

    Thanks a lot Sir for explaining very well.

  • @tchipilev9
    @tchipilev9 7 лет назад

    Very good explanation. Thank you dude !

  • @P0mpal0
    @P0mpal0 7 лет назад

    !Very clear explanation, thanks

  • @ajayjagdale2010
    @ajayjagdale2010 8 лет назад

    Very good explaination

  • @SomethingWOW0
    @SomethingWOW0 Год назад

    this video explanation was boom boom bummer. Not a short and sweet. I am going to sleep, see you tomorrow .

  • @avinashsharma5942
    @avinashsharma5942 Год назад

    Is there any difference between enumerator and yield coz they both perform stateful iteration

  • @MrJojo1089
    @MrJojo1089 9 лет назад +4

    A nice one. am just bit confused why did you need an explicit casting while creating the IEnumerable?The list was anyway of int right???

    • @Grygier94
      @Grygier94 8 лет назад +2

      It's not about int, it's about IEnumerable. Because List implements more interfaces, not only IEnumerable and generally has more features. So when you store the reference of list in IEnumerable you won't have access to all List features, just the features IEnumerable implements. You got to cast it explicitly because you limit it functionality.

    • @MerinNakarmi
      @MerinNakarmi 6 лет назад

      By limiting the functionality, does it have any benefit, like in terms of time and memory?

  • @VijayKumar-fs1mm
    @VijayKumar-fs1mm 10 лет назад

    Very good explanation, Thank you.....

  • @seanshimon
    @seanshimon 10 лет назад

    That example very good. Thanks.

  • @maheswarreddy.madithati
    @maheswarreddy.madithati 10 лет назад

    Very good video...........

  • @manjeetnandal1
    @manjeetnandal1 5 лет назад

    Great sharing...

  • @pankajjha1914
    @pankajjha1914 4 года назад

    thnku sir. it was very helpful.

  • @phantomapprentice6749
    @phantomapprentice6749 2 года назад

    Best teacher

  • @Mckandy47
    @Mckandy47 7 лет назад

    Thalaivaaa. You are great !!!

  • @korlakuntanagendrababu2432
    @korlakuntanagendrababu2432 Год назад

    Nice explanation

  • @dilshadansari8397
    @dilshadansari8397 9 лет назад

    Great Example..thanks alot..

  • @sdss315
    @sdss315 12 лет назад +1

    This is nice, I learned it,
    Thank you sir !

  • @salimshaiks
    @salimshaiks 9 лет назад

    Really helpful video....Thanks a ton.

  • @vexedev
    @vexedev 11 лет назад +1

    Maaaaan, THIS IS A TUTORIAL!!! Amaaaxxxxing :D

  • @SushrutKanetkar
    @SushrutKanetkar 7 лет назад

    Thanks ! Very clear explanation.

  • @sravankumar131
    @sravankumar131 6 лет назад

    Nice explanation...Thanks alot sir...

  • @tornadoofthoughts
    @tornadoofthoughts 7 лет назад

    Great explanation!

  • @venkatasaisrikarganugapati7567
    @venkatasaisrikarganugapati7567 8 лет назад

    Decent Explanation.

  • @ManasTunga
    @ManasTunga 11 лет назад

    I think it is completely base lase to compare IEnumerable interface with the IEnumerator
    interface, and to conclude that the former doesn't remembers the cursor position and later does.

  • @davidbarth80
    @davidbarth80 8 лет назад +1

    in practice where would you apply the technique to pass the enumator to another function?

    • @manchusandy1
      @manchusandy1 3 года назад

      I'm also looking for the same bro. Please respond to this comment in case you found the answer.

  • @brynarn
    @brynarn 5 лет назад

    Love your videos

  • @aspnet4456
    @aspnet4456 7 лет назад

    Good explanation. Thanks!!!

  • @Benjam901
    @Benjam901 11 лет назад

    You cleared up a lot for me, thank you

  • @factworld4375
    @factworld4375 6 лет назад

    Thanks sir ji.
    Loved the way u have explained it.

  • @rtrs5413
    @rtrs5413 3 года назад

    Please make a video on iqueryable and idisposable because you are best

  • @InshuMussu
    @InshuMussu 9 лет назад

    your second example made me clear

  • @joepadz2001
    @joepadz2001 8 лет назад

    good explanation.

  • @nupurmehra8987
    @nupurmehra8987 7 лет назад

    Really nice video

  • @minhaj040182
    @minhaj040182 6 лет назад +6

    Total Out of Context.
    IEnumerable is only forward loop and commonly used to list any thing without user interfere while IEnumerator is bidirectional that is Forward and Backward and commonly used in paging view so that user can move forward or backward or reset while can not achieve by iEnumerable.

    • @dnfvideo
      @dnfvideo  6 лет назад +3

      IEnumerator does not have a back method as such. So its not REALLY Bidirectional

  • @rajeevjha3714
    @rajeevjha3714 6 лет назад

    Nicely explained.

  • @abhinandan4444
    @abhinandan4444 5 лет назад

    Thanks for the explanation however, IEnumerator seems similar to Yield since both maintain state iteration state.
    What could be the possible difference between them and in what scenarios we should specifically use them?
    Thanks in advance

  • @shishirmathew1999
    @shishirmathew1999 5 лет назад +1

    Error in 12:25, In place of IEnumerable to IEnumerator remembers its state.

  • @maximus392
    @maximus392 10 лет назад

    neat and good example

  • @lifeinanutshell28
    @lifeinanutshell28 5 лет назад

    i love your explanation! thank you so much! you saved me too ... :)