I've read articles that say use ICollection<T>
if you want the functionality of IEnumerable<T>
, but also want the Count
property.
However since the extension methods in System.Linq.Enumerable
provide methods such as ElementAt()
, why wouldn't you just use an IList<T>
instead, since that uses an indexer?
Seems to me that ICollection<T>
can do what IList<T>
can do, just in a much more verbose and less readable way.
What scenario would it be more readable/more efficent, more adhering to SOLID principles, or some how better in any way to use ICollection<T>
over IList<T>
?
EDIT:
The duplicate question's answers do not answer my question since they avoid talking about the fact that ICollection<T>
can do what IList<T>
does but in a much uglier way.
If they both do the same thing, why not just use the cleaner IList<T>
?
I received much better answers here: https://www.reddit.com/r/csharp/comments/dl9xao/why_use_icollectiont_over_ilistt/