Can anyone please explain to me what is the difference between IEnumerable & IEnumerator ,
and how to use them?
Thanks!!!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Generally, an
IEnumerableis an object which can be enumerated, such as a list or array. AnIEnumeratoris an object that stores the state of the enumeration.The reason they’re not one and the same is that you could have multiple enumerations over the same object at the same time – even in a single-threaded application. For example, consider the following code:
This would work fine if
mylistis a proper implementation ofIEnumerable, but it would fail ifmylistreturned itself as the enumerator.