When implementing the INotifyPropertyChanged
interface in its most basic form, most people seem to implement it like this::
public virtual void OnPropertyChanged(string propertyName)
{
var propertyChanged = PropertyChanged;
if (propertyChanged != null)
{
propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
My question is: Why the extra assignment of var propertyChanged = PropertyChanged;
? Is it just a matter of preference, or is there a good reason for it? Surely the following is just as valid?
public virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}