Can anyone tell me when I should use either.
For example, I think I should use an IList when I want to access the .Count of the collection or an individual item, correct?
Thank you.
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 speaking, you should try and use the least specific type that suits your purpose.
IEnumerableis less specific thanIList(IListimplementsIEnumerable) so unless you want something specific fromIList(such asCountas you suggest, or perhapsAdd,Delete, etc), I’d useIEnumerable.One benefit of remaining with
IEnumerableis that you can write iterator methods to return this type (look up “yield return” and iterator methods if you are not familiar with them). This allows you to write very memory efficient “pipelines” for your loops.