Generally, it's better to return IEnumerable
, as long as that has everything the caller needs.
IEnumerable
is foreachable, which is all that's needed for many consumers. It's also read-only, which is often a good thing -- it means you can sometimes optimize by returning your actual backing collection, without worrying too much about someone modifying it without telling you.
However, if the consumer needs methods that aren't on IEnumerable
, then IList
might make more sense. For example, the caller may want to call Contains
, which isn't on IEnumerable
. Or the caller may want to index into the list, rather than iterating it from start to finish.
But you can do Contains and indexing on IEnumerable
too, via LINQ's Contains and ElementAt extension methods. So there's a question of degree here. If the caller only needs to ask one question that isn't available on IEnumerable
, like "is this empty", then return an IEnumerable
and use the Any extension method. But if the caller uses IList
operations extensively, return IList
.