Is returning IListT worse than returning T or ListT?
Data Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.
Introduction
Choosing collection return types in C# APIs is a design decision, not just syntax preference. Returning IList<T>, List<T>, or T[] communicates different guarantees about mutability, performance, and caller expectations. The best choice depends on your contract, not on a blanket rule.
Start from API Contract, Not Implementation
A public method should expose only what callers need. If consumers only need enumeration, return IEnumerable<T> or IReadOnlyList<T>. If consumers must edit elements by index, IList<T> may be appropriate.
Key idea:
- return the narrowest type that matches required operations,
- keep implementation type private so you can change internals later.
Example:
This contract allows internal use of List<User>, arrays, or other storage without breaking callers.
IList<T> vs List<T> vs T[]
Returning List<T>
Returning List<T> exposes concrete behavior and mutable methods such as Add or Remove. That can be useful for internal APIs but often too permissive for public contracts.
Risk: callers may mutate returned data and assume ownership semantics you did not intend.
Returning IList<T>
IList<T> hides concrete type but still exposes mutability operations. It offers flexibility of implementation while signaling index-based mutable access.
This is not inherently slower. Interface dispatch overhead is usually negligible compared with allocation and data processing costs.
Returning T[]
Arrays provide compact memory and fast indexed access. They are fixed-size but still mutable element-by-element.
Arrays work well when size is stable and interop or serialization expects array shapes.
When IList<T> Is a Good Choice
Use IList<T> when all of these are true:
- callers need index access,
- callers need mutation,
- you want to hide concrete collection type.
If callers should not mutate, IList<T> is usually too broad. Prefer IReadOnlyList<T> instead.
This creates a clearer contract and prevents accidental writes through API surface.
Performance Reality
Most performance questions here are dominated by copying and allocation, not by choosing interface versus concrete return type.
Potential costs to consider:
- returning a defensive copy each call,
- converting between list and array frequently,
- repeated enumeration over deferred queries.
Example of avoidable copying:
If data is immutable for caller purposes, return cached read-only view once.
Practical API Patterns
For library and service boundaries:
- read-only indexed result:
IReadOnlyList<T> - streaming query result:
IEnumerable<T> - mutation required by caller:
IList<T>or custom command methods - high-performance fixed-size results:
T[]
For internal private methods, returning List<T> can be fine if it keeps implementation simple.
Example balanced approach:
Callers can read products but must use explicit service operations for mutation.
Binary Compatibility and Future Changes
Returning interface types can improve API longevity. If you return List<T> today and later want a different structure, callers may depend on list-specific methods and break.
Returning IReadOnlyList<T> or IEnumerable<T> keeps migration paths open.
This matters in shared packages where breaking API changes carry rollout cost.
Common Pitfalls
A common pitfall is returning IList<T> while expecting consumers not to mutate. The type itself permits mutation, so callers are not wrong to use it.
Another issue is defensive copying on every call for fear of mutation. This can create heavy allocation pressure in hot paths.
Teams also conflate interface return types with slower execution. In most business code, the overhead difference is insignificant.
Finally, exposing List<T> from public APIs leaks implementation details and reduces future flexibility.
Summary
IList<T>is not inherently worse thanList<T>orT[].- Choose return types based on contract: mutability, indexing, and abstraction needs.
- Prefer
IReadOnlyList<T>when callers need indexing without mutation. - Performance problems usually come from copying and allocation, not interface dispatch.
- Keep public APIs narrow so implementation details can evolve safely.
Related reading
- Is the order guaranteed for the return of keys and values from a LinkedHashMap object?
- Is the runtime of BFS and DFS on a binary tree ON?
- Is the sorting algorithm used by .NET's Array.Sort method a stable algorithm?
- Is there a bug in java.util.Stack's Iterator?
- Is shifting bits faster than multiplying and dividing in Java? .NET?
- Is String.Contains faster than String.IndexOf?
- Is Task.Delay non blocking?
- Is Task.Factory.StartNew guaranteed to use another thread than the calling thread?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.