What is the requirement for a collection in order that we can put a foreach on it in c#? What are the types on which we can put for each?
EDIT 1: Can anybody come up with a sample code of a User Defined Collection on which Foreach is Implemented.
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.
It implements
IEnumerableorIEnumerable<T>Edit: there is the wrinkle that if the type has method called GetEnumerator() that returns an IEnumerator then it is also usable in a foreach. see http://brendan.enrick.com/post/Foreach-IEnumerable-IEnumerator-and-Duck-Typing.aspx