, :
, - , , - .
When changing this value inside (inside the class) it may be a valid time to use a direct backup directly if you intend to skip all the checks and events from the public setter. I like to say, "I'm an instance of a class, I know what I'm doing." In this way, the public setter acts like a guard dog, disinfecting the external entrance, while I can still set the property inside what I need.
class X
{
private int y;
public X(int number)
{
y = GetYValueFromDB();
}
public int Y {
get{ return y};
set {
if (ComplexValidation(value)
{
RaiseOnYPropertyChanged();
y = value;
}
}
}
source
share