C# › Collections

What is the difference between IEnumerable<T>, ICollection<T>, and IList<T> in the collection interface hierarchy?

Intermediate

Answer

IEnumerable<T> only guarantees the ability to ITERATE (foreach); ICollection<T> extends it with Count, Add, Remove, and Contains; IList<T> extends ICollection<T> further with INDEX-based access (this[int index]) and Insert/RemoveAt — each level adds more capability at the cost of requiring more from the underlying implementation.
void ProcessReadOnly(IEnumerable<int> items) { /* can only iterate */ }
void ProcessCountable(ICollection<int> items) { Console.WriteLine(items.Count); }
void ProcessIndexable(IList<int> items) { Console.WriteLine(items[0]); }
Real-world example Accepting the loosest interface (IEnumerable<T>) a method's parameter genuinely needs, maximizing which concrete collection types can be passed in.

Common follow-ups: Why is it generally considered good practice to accept the LEAST specific interface your method actually requires?