Advertisement
Intermediate C#, Collections

What is the difference between IEnumerable, ICollection and IList?

Short answer

IEnumerable supports iteration only; ICollection adds Count/Add/Remove; IList adds indexed access and Insert. Accept the least specific type your method needs.

Save C# mock interview
Advertisement
AModel answer
IEnumerable supports iteration only; ICollection adds Count/Add/Remove; IList adds indexed access and Insert. Accept the least specific type your method needs.
void Print(IEnumerable<int> xs) {}
int First(IList<int> xs) => xs[0];
Real-world example
Accepting IEnumerable<T> in APIs keeps callers flexible (arrays, lists, LINQ).