Is there anything magic about ReadOnlyCollection

Posted by EsbenP on Stack Overflow See other posts from Stack Overflow or by EsbenP
Published on 2009-09-11T09:06:19Z Indexed on 2010/04/20 15:43 UTC
Read the original article Hit count: 514

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.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about interface