Reputation: 15807
I have read the following question, which asks about the different between a Delegate and an EventHandler: Difference between EventHandler and delegete void(). There are a few other questions I have read on here this afternoon.
I understand that a Delegate is a pointer to a function and is multicast. I have read that am Event Handler "is a" delegate. I notice that it has this signature:
Public Delegate Sub EventHandler ( _
sender As Object, _
e As EventArgs _
)
However, it does not inherit from Delegate. I do make use of the Handles keyword in VB.NET e.g. Handles Button1.Click. What is the point of an Event Handler? Is it simply a delegate with two arguements i.e. Object and EventArgs? Why does the EventHandler class not inherit from Delegate?
Upvotes: 1
Views: 102
Reputation: 911
A Delegate is not a class. And as such it can not be inherited.
EventHandler as you observed is just a delegate with a well known signature, and thus defines a uniform way of event firing and handling.
Upvotes: 1
Reputation: 3635
An event handler is the routine that is going to execute when an event occurs.
A delegate is a reference to a routine.
If you have no handler the delegate can't reference anything.
Delegates are the easy way for VB to handle function pointers. EventHandler does not need to inherit from delegate because it is a function, not a pointer.
Upvotes: 0