I came over a weird behavior of C# compiler. Can you elaborate why this code just works fine?
public class A
{
public void Test()
{
var x = new B
{
// assigning to a read only property
ReadOnlyProperty = {new KeyValuePair<int, int>(1, 1)}
};
}
}
class B
{
public IDictionary<int,int> ReadOnlyProperty { get; }
}
The expected behavior is not being able to assign anything to readonly properties.