If I write something like the code below,
class MainClass { static EventHandler _myEvent= delegate{}; static event EventHandler MyEvent { add{_myEvent += value;} remove{_myEvent -= value;} } public static void Main (string[] args) { MyEvent(null,EventArgs.Empty); } }
the compiler will complain: Error CS0079: MainClass.MyEvent event MainClass.MyEvent' can only appear on the left hand side of + =' or `- = '.
Why is something so strange as it even exists? If I cannot fire the event directly, why should I use such a thing in the first place? Is this a mistake (I use mono) or an intentional subtle design? Can someone teach me the rationale for this? Thanks in advance.
source share