Getter without body, Setter with

后端 未结 5 652
死守一世寂寞
死守一世寂寞 2021-01-01 11:21

I have a property which is currently automatic.

public string MyProperty { get; set; }

However, I now need it to perform some action every

5条回答
  •  长情又很酷
    2021-01-01 12:02

    You need to use a property with backing field:

    private string mMyProperty;
    public string MyProperty
    {
        get { return mMyProperty; }
        set
        {
            mMyProperty = value;
            PerformSomeAction();
        }
    }
    

提交回复
热议问题