i am quite confused about the differences between the various types in the C# language. specifically
- IEnumerable
- IEnumerator
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.
IEnumerable<T>represents a sequence which can be enumerated – such as a list.IEnuerator<T>effectively represents a cursor within a sequence.So imagine you have a sequence – you can iterate over that with several “cursors” at the same time. For example:
Here,
List<string>implementsIEnumerable<string>, and theforeachloops each callGetEnumerator()to retrieve anIEnumerator<string>. So when we’re in the middle of the inner loop, there are two independent cursors iterating over a single sequence.