I have looking at an old piece of code and cannot somehow understand the following:
public event EventHandler NameChanged;
#endregion
#region protected void OnNameChanged(EventArgs args)
/// <summary>
/// Raises NameChanged event.
/// </summary>
/// <param name="args">Event arguments.</param>
protected void OnNameChanged(EventArgs args)
{
EventHandler eh = this.NameChanged;
if (eh != null)
{
eh(this, args);
}
}
Why is the event raised by an invocation of the delegate? Could I not simply call the event itself (NameChanged) as usual?
EDIT: I can see this is also suggested on MSDN: https://learn.microsoft.com/en-us/dotnet/standard/events/