The article http://msdn.microsoft.com/en-us/magazine/dd419663.aspx has the following code sample:
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
var e = new PropertyChangedEventArgs(propertyName);
handler(this, e);
}
}
My question is what is gained by introducing the variable 'handler' - the following code seems to work fine:
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged!= null)
{
var e = new PropertyChangedEventArgs(propertyName);
PropertyChanged(this, e);
}
}