使用auto属性设置器

时间:2017-07-24 09:24:06

标签: c# properties getter-setter

是否可以在设置器中运行其他代码,仅使用auto implemented properties?即像这样,只使用自动属性:

// I Would like to get rid of this...
int privateField 

// ...and only have this
public int PrivateField 
{
    get { return privateField; }
    set
    {
        privateField = value;
        functionDependingOnSetter(value);
    }
}

(如果不清楚,我希望在调用属性setter时运行函数functionDependingOnSetter()。)

0 个答案:

没有答案
相关问题