Why does List <T> implement the IReadOnlyList <T> interface?
Why IReadOnlyList<T> List<T> implement IReadOnlyList<T> , although List<T> not read-only?
It allows you to set only a proxy server to read only this list, so that you can pass this link elsewhere and know that the code will not mutate the list. (Technically, he might try to return it to something like List and change it, but he shouldn't do that.)
It also allows the method to specifically indicate that although it must accept the list, it will not mutate it.
Having a read-only interface also allows this interface to be covariant, unlike List or IList .
You can think of it in terms of subtyping. A regular list can be a read-only list if you do not modify it, i.e. List<T> is a subtype of IReadOnlyList<T> (I'm not sure if C # types really carry this). When entering text, you can indicate that a particular piece of code will not make any changes to the list.
Another example of this kind is C, where you can pass an int method that takes a const int or pass a int to a method that expects a volatile int . Consideration of the argument more strictly than necessary is not harmful.