The IList<T>
interface includes access by index in addition to operations not supported by the SortedList<TKey, TValue>.Keys
property such as Add
, Remove
, and Insert
.
A ReadOnlyCollection<T>
, such as the return value of List<T>.AsReadOnly
, implements IList<T>
and therefore offers access by index but hides illegal operations like Add
, etc. by implementing them explicitly. Furthermore, it is merely a wrapper for the underlying list; so it does not create a copy and should therefore (I would assume) not incur any real performance hit.
Any idea why SortedList<TKey, TValue.Keys
isn't a ReadOnlyCollection<TKey>
? (And for that matter why the Values
property isn't a ReadOnlyColllection<TValue>
?)