When I\'m writing my DAL or other code that returns a set of items, should I always make my return statement:
public IEnumerable GetRecentItems
In general, you should require the most generic and return the most specific thing that you can. So if you have a method that takes a parameter, and you only really need what's available in IEnumerable, then that should be your parameter type. If your method could return either an IList or an IEnumerable, prefer returning IList. This ensures that it is usable by the widest range of consumers.
Be loose in what you require, and explicit in what you provide.
List
) for the return
values and the most generic type for input parameters even in case of collections.IReadOnlyList
or IReadOnlyCollection
as the return value type.More