Here is Action delegate. Thus three writeline methods are called
@MilanJovanovicTech9 күн бұрын
✅
@yiliang970212 күн бұрын
delegate supports +=opetator. all of the funtions will be triggered.
@MilanJovanovicTech12 күн бұрын
✅
@rusektor13 күн бұрын
All 3 will be run thanks to broadcasting 😊
@MilanJovanovicTech12 күн бұрын
✅
@rusektor12 күн бұрын
@@MilanJovanovicTech It's also interesting: when I write the following code, Visual Studio squiggled last line with warning "Dereference of a possibly null reference": Action del1 = () => Console.WriteLine("Task 1"); Action del2 = () => Console.WriteLine("Task 2"); Action del3 = () => Console.WriteLine("Task 3"); var func = del1; func += del2; func += del3; func(); Console.WriteLine("remove del2..."); func -= del2; func(); I then realized that this is due to the fact that there can be a situation when there will be no delegates to run. The solution is simple: func?.Invoke(); 😉
@sameerband293312 күн бұрын
All three methods would be executed. We have event to enforce multicast delegate so that we don't accidently assign a delegate instead of subscribing. I. E. Enforce += and prevent =
@MilanJovanovicTech12 күн бұрын
✅
@dinorme12 күн бұрын
easy, its a delegate so it will print 3 of them :3