Is there anything magic about ReadOnlyCollection
- by EsbenP
Having this code...
var b = new ReadOnlyCollection<int>(new[] { 2, 4, 2, 2 });
b[2] = 3;
I get a compile error at the second line. I would expect a runtime error since ReadOnlyCollection<T> implements IList<T> and the this[T] have a setter in the IList<T> interface.
I've tried to replicate the functionality of ReadOnlyCollection, but removing the setter from this[T] is a compile error.