Do not miss our Interview Question video series 30 Important C# Interview Questions : th-cam.com/video/BKynEBPqiIM/w-d-xo.html 25 Important ASP.NET Interview Questions : th-cam.com/video/pXmMdmJUC0g/w-d-xo.html 25 Angular Interview Questions : th-cam.com/video/-jeoyDJDsSM/w-d-xo.html 5 MSBI Interview Questions : th-cam.com/video/5E815aXAwYQ/w-d-xo.html
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 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.
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
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.
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!
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
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.
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.
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.
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.
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.
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.
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.
I don't seem to get the point, why cast oyears to IEnumerable and still use a for each loop to iterate through when you could have used the list and done the same thing?
You never had the need to find Nth element in a list ??, or even better - on what position is the element X in a list ?? Funny how I always used a foreach, and then used an outside counter to "update" the current position, in the foreach-loop itself till a certain condition is met :P
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.
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.
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
I still dont understand why and when to use IEnumerable or IEnumerator. I see all you've done can be easily achieved with the List above....Please enlight me on this.
For example you have a program in which you want to loop through some list but you want to restrict the collaborator from accessing methods from the List (Clear, Remove At etc). You will use IEnumerable to achieve this. Basically what collaborator can't do know is Clear list which ensures there will be no unexpected behaviour of the program.
For example you have a program in which you want to loop through some list but you want to restrict the collaborator from accessing methods from the List (Clear, Remove At etc). You will use IEnumerable to achieve this. Basically what collaborator can't do know is Clear list which ensures there will be no unexpected behaviour of the program.
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.
Do not miss our Interview Question video series
30 Important C# Interview Questions : th-cam.com/video/BKynEBPqiIM/w-d-xo.html
25 Important ASP.NET Interview Questions : th-cam.com/video/pXmMdmJUC0g/w-d-xo.html
25 Angular Interview Questions : th-cam.com/video/-jeoyDJDsSM/w-d-xo.html
5 MSBI Interview Questions : th-cam.com/video/5E815aXAwYQ/w-d-xo.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! :)
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 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
Very well explained in simplistic words.
This truely signifies the role of a good teacher.
Shiv sir you are the best !!! Keep it up...
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.
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
Now that I understood what I need to.... I am all set for Nirvana - Guru ji with your blessings.
I was very confused between IEnumerable and IEnumerator before the video, I had a very clear explanations from your videos in depth.Thank You.
I had these exact questions and you have answered really well with simple and clear explanation. 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
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.
You are a life saver. Finally, I get the difference between these two now.
Excellent explanation sir ...Thank you 🙏
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
The video was awesome...i was finding it difficult to understand the difference from many sites, this video was crisp and clear...kudos
Thank your clear explation sir thumbs up from PH🇵🇭
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.
You are a true professional and an excellent explanation
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 !
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#.
Well done. No words to appreciate. Long time confusion is cleared..
Cleared a very important concept. Thanks a lot.
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?
Thank you very much now I got very clear idea about these two interfaces thanks once again
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.
Better than most other explanations!
Great explanation ...u reduced my stresssss..
Love these videos. Very comprehensive explanations.
Best example I have seen,it's registered in my mind.
Excellent explanation of the difference between the two. Thanks.
You always give excellent examples and analogy, thanks a lot for sharing
good entertaining explanations- I use it for looping through controls in forms apps but I didn't know what differences between the two were
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 good explanation, thank you.
Thanks I have been looking for a decent explanation of the difference between the two collections.
Very good Explanation for Enumerator and Enumerable
Please try to make video on MVC Layout. which should not refresh entire layout for each request
Very nice explanation. Thanks for the video.
Very well explained the details.
Super shiv sir thanks for making my learning easy. I got one doubt to make the ienumerable remember cursor position can we use getenumerator()?
Clear and concise explanation.. Awesome..
Very good video. As always, well explained, easy to follow code and example. Thanks for sharing with the world.
it really help me to understand basic difference, Thanks,
Wow Sir Awesome ! Nicely explained loved it 😊😊
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?
IEnumerable internally use IEnumerator then why it does not maintain the state
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
Perfect explanation. Thank you
I don't seem to get the point, why cast oyears to IEnumerable and still use a for each loop to iterate through when you could have used the list and done the same thing?
You never had the need to find Nth element in a list ??, or even better - on what position is the element X in a list ??
Funny how I always used a foreach, and then used an outside counter to "update" the current position, in the foreach-loop itself till a certain condition is met :P
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
Super explanation bro..
Superb explanation
Very nice and clear explanation... Thanks a lot
Thanks a lot Sir for explaining very well.
this video explanation was boom boom bummer. Not a short and sweet. I am going to sleep, see you tomorrow .
Please make a video on iqueryable and idisposable because you are best
That example very good. Thanks.
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.
Very good explaination
Very good explanation, Thank you.....
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
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.
Thanks, you made the Difference clear!
Thanks a lots keep posting for us please 🙏👍 ☺️
i love your explanation! thank you so much! you saved me!
I still dont understand why and when to use IEnumerable or IEnumerator. I see all you've done can be easily achieved with the List above....Please enlight me on this.
For example you have a program in which you want to loop through some list but you want to restrict the collaborator from accessing methods from the List (Clear, Remove At etc). You will use IEnumerable to achieve this. Basically what collaborator can't do know is Clear list which ensures there will be no unexpected behaviour of the program.
For example you have a program in which you want to loop through some list but you want to restrict the collaborator from accessing methods from the List (Clear, Remove At etc). You will use IEnumerable to achieve this. Basically what collaborator can't do know is Clear list which ensures there will be no unexpected behaviour of the program.
@@PramodSingh-kc1ne Wtf you copy pasted the same comment from above a year later?
Thanks for making this much clearer. I appreciate your time.
thnku sir. it was very helpful.
Is there any difference between enumerator and yield coz they both perform stateful iteration
Very good explanation. Thank you dude !
Simple and clear explained. Thank You!
!Very clear explanation, thanks
excellent lecture clear view
Nice explanation...Thanks alot sir...
Nice explanation
Very good video...........
u r superb sir.. Keep helping us
Really helpful video....Thanks a ton.
This is nice, I learned it,
Thank you sir !
Wow, very good! Would you do a video on the ICollection interface, the IList interface and the IDictionary interface?
You explaine very well peace
Best teacher
Tanks for this show. I learned a lot with video.
Great Example..thanks alot..
Good explanation. Thanks!!!
Great sharing...
wouldn't it be the same if somehow u change the method you do "yield return" on IEnumerable?
seeing your "c# Yield keyword". which would be better?
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.
Thalaivaaa. You are great !!!
Thanks sir ji.
Loved the way u have explained it.
Thanks ! Very clear explanation.
Decent Explanation.
Wonderful explanation , very informative
Thank you for sharing!
Love your videos
Great explanation!
use for loop with index to find position when using ienurable
Maaaaan, THIS IS A TUTORIAL!!! Amaaaxxxxing :D