Reputation: 13614
I have started working with ASP.NET controls and there appeared a question: "why events in ASP controls are defined as delegates, and not as methods"?
Upvotes: 2
Views: 106
Reputation: 1183
Because an event must point to the function that it fires somehow and in C# this mechanism is achieved by delegates.
In response to the comment:
Then, why is such not a case with Java that uses only methods to fire events?
Because Java uses the old traditional event pattern (like in C++). C# delegates are easier to use and also allow you to point to a static function rather than forcing the use of a class method.
Upvotes: 3