Thursday, September 08, 2005

Demistifying events

I ran today into a really annoying constraint regarding events. It is known as error CS0070, and says that events can only be invoked from the class in which they were declared. So even if you have a protected event (with public accessors to add/remove listeners) in a base class, derived classes can not directly use that event.
Googling a bit on this issue (mostly to find other people complaining about it, 'cause it was pretty clear that's the way it is and there's nothing I can do about it), I came accross a pretty nice post that could help explain some of the issues with events that are not all that clear in MSDN. I haven't read it from top to bottom, but from the skimming I did it looks pretty good. Enjoy!
C# events vs. delegates

No comments: