Hi Geeks,
Here are few points which I learnt about IEnumerable and IEnumerator.
- IEnumerable uses IEnumerator internally.
- IEnumerable doesnt know which item/object is executing.
- Whenever we pass IEnumerator to another function ,it knows the current position of item/object.
- Whenever we pass IEnumerable collection to another function ,it doesn't know the current position of item/object(doesn't know where I am)
- IEnumerable have one method GetEnumerator()
IEnumerator have one Property current and two methods Reset and MoveNext.
In simple words: If you want to loop through with the collection one by one and you are not interested in the current cursor position then should opt
Enumerable.Because code is simple and short.
And if you are keen to know the current position of object then should go for IEnumerate.