I’m wondering what benefits this code has:
private int _TestID;
public int TestID
{
get
{
return _TestID;
}
set
{
if(_TestID != value)
{
_TestID = value;
}
}
}
vs. this:
private int _TestID;
public int TestID
{
get
{
return _TestID;
}
set
{
_TestID = value;
}
}
It seems to me that this was done in the name of efficiency (only setting if different), but wouldn’t the test take as long (or longer) that the initial set? I’m not sure if I’m missing something here, but would love to hear any comments and explanations.
It is useful when you combine it with a RaisePropertyChanged(“TestID”) (inside the if, after the field value is set) event pattern often seen with WPF or other databinding solutions.