Can anyone answer why in the Microsoft Documentation for Collection (T) the following line is defined
EventHandler<DinosaursChangedEventArgs> temp = Changed;
What's it's advantage over directly referring to Changed instead? thanks!
public class Dinosaurs : Collection<string>
{
public event EventHandler<DinosaursChangedEventArgs> Changed;
protected override void InsertItem(int index, string newItem)
{
base.InsertItem(index, newItem);
EventHandler<DinosaursChangedEventArgs> temp = Changed;
if (temp != null)
{
temp(this, new DinosaursChangedEventArgs(
ChangeType.Added, newItem, null));
}
}
I can't seem to figure out why the below approach isn't used ?
public class Dinosaurs : Collection<string>
{
public event EventHandler<DinosaursChangedEventArgs> Changed;
protected override void InsertItem(int index, string newItem)
{
base.InsertItem(index, newItem);
if (Changed != null)
{
Changed(this, new DinosaursChangedEventArgs(
ChangeType.Added, newItem, null));
}
}