I wish to return an ordered list of items from a method. Should my return type be IEnumerable or IList?
Share
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.
There is a hierarchy here:
You want to aim for the least possible coupling, so return an
IEnumerable<T>if that is enough. It probably will be.Return an
IList<T>if the situation requires that the caller gets a List that it can use to Add/Insert/Remove. But even then it might be better if the caller created his own List from the IEnumerable collection.