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.
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
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! :)
Very well explained in simplistic words.
This truely signifies the role of a good teacher.
Shiv sir you are the best !!! Keep it up...
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.
thank you for this concept.
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
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!
Was going to comment the same
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.
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!
I was very confused between IEnumerable and IEnumerator before the video, I had a very clear explanations from your videos in depth.Thank You.
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
I had these exact questions and you have answered really well with simple and clear explanation. Thank you!
The video was awesome...i was finding it difficult to understand the difference from many sites, this video was crisp and clear...kudos
You are a life saver. Finally, I get the difference between these two now.
Now that I understood what I need to.... I am all set for Nirvana - Guru ji with your blessings.
You are a true professional and an excellent explanation
Thank your clear explation sir thumbs up from PH🇵🇭
Well done. No words to appreciate. Long time confusion is cleared..
Love these videos. Very comprehensive explanations.
now i can die in peace
RIP in peace.
:D
This made me laugh so hard. But its so true. Programming can get so confusing at times
LOL :D
:p
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.
great work man. hardworking and talented people like you deserve subscribers and appreciation rather than those loser tiktokers.
Really nice video!! you have mentioned that IEnumeratble internally uses IEnumerator, so why it does not remember the current cursor position?
Better than most other explanations!
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.
we can use foreach with oyears right? then why you convert oyears to IEnumerable explicity?
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#.
You always give excellent examples and analogy, thanks a lot for sharing
Thanks a lots keep posting for us please 🙏👍 ☺️
Great explanation ...u reduced my stresssss..
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.
Thank you very much now I got very clear idea about these two interfaces thanks once again
Excellent explanation sir ...Thank you 🙏
Thanks I have been looking for a decent explanation of the difference between the two collections.
Excellent explanation of the difference between the two. Thanks.
Clear and concise explanation.. Awesome..
Very well explained the details.
Best example I have seen,it's registered in my mind.
good entertaining explanations- I use it for looping through controls in forms apps but I didn't know what differences between the two were
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.
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.
Very good Explanation for Enumerator and Enumerable
Tanks for this show. I learned a lot with video.
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.
it really help me to understand basic difference, Thanks,
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.
Very nice explanation. Thanks for the video.
Very nice and clear explanation... Thanks a lot
Perfect explanation. Thank you
Thanks for making this much clearer. I appreciate your time.
Wow Sir Awesome ! Nicely explained loved it 😊😊
Very good video. As always, well explained, easy to follow code and example. Thanks for sharing with the world.
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 ?"
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.
@@monochromenight8943 that was really helpful, thanks !
i love your explanation! thank you so much! you saved me!
Very good explanation
Superb explanation
Thanks, you made the Difference clear!
excellent lecture clear view
Cleared a very important concept. Thanks a lot.
Super shiv sir thanks for making my learning easy. I got one doubt to make the ienumerable remember cursor position can we use getenumerator()?
Simple and clear explained. Thank You!
Please try to make video on MVC Layout. which should not refresh entire layout for each request
u r superb sir.. Keep helping us
Super explanation bro..
Thanks a lot Sir for explaining very well.
Very good explanation. Thank you dude !
!Very clear explanation, thanks
Very good explaination
this video explanation was boom boom bummer. Not a short and sweet. I am going to sleep, see you tomorrow .
Is there any difference between enumerator and yield coz they both perform stateful iteration
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???
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.
By limiting the functionality, does it have any benefit, like in terms of time and memory?
Very good explanation, Thank you.....
That example very good. Thanks.
Very good video...........
Great sharing...
thnku sir. it was very helpful.
Best teacher
Thalaivaaa. You are great !!!
Nice explanation
Great Example..thanks alot..
This is nice, I learned it,
Thank you sir !
Really helpful video....Thanks a ton.
Maaaaan, THIS IS A TUTORIAL!!! Amaaaxxxxing :D
Thanks ! Very clear explanation.
Nice explanation...Thanks alot sir...
Great explanation!
Decent Explanation.
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.
in practice where would you apply the technique to pass the enumator to another function?
I'm also looking for the same bro. Please respond to this comment in case you found the answer.
Love your videos
Good explanation. Thanks!!!
You cleared up a lot for me, thank you
Thanks sir ji.
Loved the way u have explained it.
Please make a video on iqueryable and idisposable because you are best
your second example made me clear
good explanation.
Really nice video
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.
IEnumerator does not have a back method as such. So its not REALLY Bidirectional
Nicely explained.
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
Error in 12:25, In place of IEnumerable to IEnumerator remembers its state.
All before you did not ear it....
neat and good example
i love your explanation! thank you so much! you saved me too ... :)