views:

45

answers:

3

why are EventHandlers designed this way?

void uxSave_Click(object sender, EventArgs e)

why not this?

void uxSave_Click(Button sender, EventArgs e)
+2  A: 

Hi, because using first way you can attach this click event to panel too. But if it is done second way if you have to controls events doing the same you need to define two events not attach one at two places Best Regards, Iordan

IordanTanev
+2  A: 

Also, keep in mind that .NET did not have generics in version 1.0. Otherwise, a reasonable design might have defined the event handler to be:

public delegate void EventHandler<TSender, TEventArgs>(TSender sender, TEventArgs e);
public event EventHandler<Control,ClickEventArgs> Click;
John Saunders
A: 

I think it's probably because you can't always assume that your sender is the type you expect it as. Someone else can call that event from somewhere else.

Steve the Plant