Assignment to readonly property in initializer list

前端 未结 3 1240
生来不讨喜
生来不讨喜 2020-12-21 10:01

Can one tell me, why the heck does it compile?

namespace ManagedConsoleSketchbook
{
    public interface IMyInterface
    {
        int IntfProp
        {
           


        
3条回答
  •  鱼传尺愫
    2020-12-21 10:35

    Because you are using the initializer which uses the setter of ItfProp, not the setter of Property.

    So it will throw a NullReferenceException at runtime, since Property will still be null.

提交回复
热议问题