List<T>
implements IReadOnlyCollection<T>
interface and provides the AsReadOnly()
method which returns ReadOnlyCollection<T>
(which in turn implements IReadOnlyCollection<T>
).
What is the usage/reason for AsReadyOnly()
? Its existence smells of one or two edge cases where just returning the list as IReadOnlyCollection<T>
is just not good enough.
At first I though it may be to prevent casting the cost-ness away but it looks like you can do that with ReadOnlyCollection<T>
's Items
accessor.
BTW. The documentation for ReadOnlyCollection<T>
type reads
Provides the base class for a generic read-only collection.
which, in my head, conflicts with having a constructor described as
Initializes a new instance of the (...) class that is a read-only wrapper around the specified list.
Update:
I did not see that ReadOnlyCollection<T>
's Items
is protected.