TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C# Coding Standard

Rule:  5@119Checked automatically with code checker

Synopsis:Return an IEnumerable<T> or ICollection<T> instead of a concrete collection class
Severity Level:5
Category:Object lifecycle


In general, you donít want callers to be able to change an internal collection, so donít return arrays, lists or other collection classes directly. Instead, return an IEnumerable<T>, or, if the caller must be able to determine the count, an ICollection<T>.


    public IEnumerable<FooBar> GetRecentItems()

is preferred to

    public List<FooBar> GetRecentItems()

Note If youíre using .NET 4.5, you can also use IReadOnlyCollection<T>, IReadOnlyList<T> or IReadOnlyDictionary<TKey, TValue>.

Literature References:
Aviva AV1130