In C #, I sometimes have to register a method for an event in the middle of sending the same event. For example, if I have a class that translates states based on successive dispatches of the same event, I might need the first state handler to unregister and register the second handler. However, I do not want the second handler to be sent before the next event trigger.
The good news is that it looks like Microsoft's C # implementation is behaving that way. Sack event registration syntax is replaced by a call to System.Delegate.Combine, which simply combines the current list of calls and the new method into a separate list and assigns an event property to it. This gives me exactly the behavior I want.
So my question is: is this guaranteed behavior by locale? I like to be able to run my C # code on other platforms under mono and, as a rule, I want to make sure that I do not make assumptions about the language standard based on its implementation.
I could not find the final information about MSDN.
If you need a specific example of what I'm saying, here is an example:
delegate void TestDelegate(); static event TestDelegate TestEvent; static void Main (string[] args) { TestEvent += TestDelegateInstanceFirst; TestEvent(); TestEvent(); } static void TestDelegateInstanceFirst () { Console.WriteLine("First"); TestEvent += TestDelegateInstanceSecond; } static void TestDelegateInstanceSecond () { Console.WriteLine("Second"); }
At least on Windows, the output is:
First First Second
source share