Is there any specific reason why indexing is not allowed in IEnumerable.
I found a workaround for the problem I had, but just curious to know why it does not allow indexing.
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.
Because it’s not.
Indexing is covered by
IList.IEnumerablemeans “I have some of the powers of IList, but not all of them.”Some collections (like a linked list), cannot be indexed in a practical way. But they can be accessed item-by-item.
IEnumerableis intended for collections like that. Note that a collection can implement both IList & IEnumerable (and many others). You generally only findIEnumerableas a function parameter, meaning the function can accept any kind of collection, because all it needs is the simplest access mode.