Hilton <no****@nospam.comwrote:
Why does:
class A
{
public event EventHandler XYZPressed;
}
class B : A
{
void Bla ()
{
this.XYZPressed (this, EventArgs.Empty)
}
}
give this compiler error:
Error 8 The event 'ABC.DEF.XYZPressed' can only appear on the left hand side
of += or -= (except when used from within the type 'ABC.DEF')
Since B *is* an A (inheritence), you should be able to do this. Right?
No. Class A is (nearly) equivalent to:
class A
{
private EventHandler XYZPressedHandlers;
public event EventHandler XYZPressed
{
add { XYZPressedHandlers += value; }
remove { XYZPressedHandlers -= value; }
}
}
Note that the delegate field is private, so you don't have access to it
from B.
Does that make more sense now? If not, read
http://pobox.com/~skeet/csharp/events.html
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too