是否可以在设置器中运行其他代码,仅使用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()
。)