I have a basic doubt. Internally how are events represented as methods or as (fields)objects. If event is a field then how one can still contain events in the interface definition.
Thanks
JeeZ
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you type this:
what the compiler generates is (simplified) this:
An event is similar to a property; a wrapper around a delegate that only allows methods to be added or removed. This is so you can’t completely re-assign the delegate and delete other people’s subscriptions to it.
All you are doing when specifying an event in an interface is that any implementing classes should have the
addandremovemethods for the event. Very similar to declaring a property on an interface, in fact.This is also why you can only call or re-assign the event in the class it is declared in – any references to the
MyEventevent within the class are re-routed to use the delegate directly, whereas outside the class you can only access theaddandremovemethods, not the delegate directly.