public delegate void Action<object?, EventArgs>(object? sender, EventArgs e);
public delegate void EventHandler(object? sender, EventArgs e);
What is the difference between those two lines? They seem to be functionally equal.
Rotabor's answer is basically correct, except for the reasoning: EventHandler
exists since .NET Framework 1.1, which did not have generics and thus also did not yet have Action<T>
. Only fully defined delegate types where allowed.
When Action
(with it's generic overloads) was added in .NET Framework 2.0, EventHandler
was kept for backwards compatibility.