I see all three used as method parameters and return types in our codebase. Which one should I pick, and does the choice actually matter?
I see all three used as method parameters and return types in our codebase. Which one should I pick, and does the choice actually matter?
Each interface adds capability on top of the one before it:
A good rule: accept the smallest interface you need, and return the most useful one you are happy to promise. If a method only loops, take IEnumerable<T>. If you return a finished list that callers should not change, return IReadOnlyList<T>.
One trap: an IEnumerable produced by LINQ is usually deferred, so the query can run again on every loop. If you will enumerate the result twice, call ToList() once and keep the list.