What is Difference between IEnumrable and IEnumrator in C#

 https://www.c-sharpcorner.com/UploadFile/219d4d/ienumerable-vs-ienumerator-in-C-Sharp/


Both of these interfaces help to loop through the collection.

The IEnumerable interface actually uses IEnumerator. The main reason to create an IEnumerable is to make the syntax shorter and simpler.


The main difference between IEnumerable and IEnumerator is an IEnumerator retains its cursor's current state.


So, if you want to loop sequentially through the collection, use an IEnumerable interface else if you want to retain the cursor position and want to pass it from one function to another function then use an IEnumerator interface.

Comments

Popular posts from this blog

What is Entity Framework?

Explain the ways to increase the performance of EF.