Skip to content

IEnumerable vs. IList

Question

Describe the difference between IEnumerable and IList or an array. Explain deferred execution.

Short interview answer

IEnumerable represents something that can be enumerated; it does not promise indexing, count, or mutation. IList adds indexed access and collection operations. Deferred execution means a query or iterator can run when it is enumerated rather than when it is declared.

Detailed answer

An array and most IList implementations materialize elements and support indexing. An IEnumerable<T> may stream elements from a file, database provider, or iterator method:

var adults = people.Where(person => person.Age >= 18); // No iteration yet.
people.Add(new Person { Age = 30 });
var count = adults.Count(); // The new person can be included here.

The Where call commonly builds a deferred pipeline; enumeration at Count() performs the work. Materialize deliberately with ToList() when a stable snapshot is required.

Sources