On the Internet, I found this code:
using System; class a { public event EventHandler Ev; public void EventStart() { EventHandler temp = Ev; if (temp != null) temp(this, EventArgs.Empty); } } class demo { static void Main() { a A = new a(); A.Ev += (o, e) => { Console.WriteLine(1); }; A.Ev += (o, e) => { Console.WriteLine(2); }; A.Ev += (o, e) => { Console.WriteLine(3); }; A.EventStart(); } } And I was very surprised by this line EventHandler temp = Ev; why is the assignment going fine? After all, an event and a delegate are two different things. The event is a field with add remove accessors that add / remove methods (delegates) to the "delegate" array. That is, if it is crude, then this assignment is something like Action a = new Action[n] . I was especially surprised that if you make a lot of subscriptions to this event, then for some reason, when you call one delegate, they all start. Explain please.
if (temp != null)you can define Ev as:public event EventHandler Ev = delegate {};- Stackvar tmp = .... if(tmp ...)is not enough. therefore, the easiest way to define is= delegate {};- Stackreadonlystill deliver. "and var tmp = .... if (tmp ...) is not enough" - why? - andreycha