You would do:
this.btSomeButton.Click += btSomeButton_OnClick; private void btSomeButton_OnClick(object sender, EventArgs e) { this.DoFunc1(); this.DoFunc2(); }
Or:
this.btSomeButton.Click += DoFunc1; this.btSomeButton.Click += DoDunc2;
Are there any hidden implications for using the second method? How, is it guaranteed that DoFunc2 () will be launched after DoFunc1 ()?
I think the first method is safer.
AFAIK there is no guarantee when it comes to the execution order of a method, and if the methods actually arrive in sequential order, the first method makes more sense.
In addition, when multiple event handlers are attached to an event, it is very easy to skip other events when detaching individual event handlers.
I would do the first too.
Perfomance , # 1 imho - , . , :
this.btSomeButton.Click += DoSomethingRelatedToDataPersistence; this.btSomeButton.Click += DoSomethingRelatedToTheDirectionTheMoonSpinsAroundTheEarth;
.. , : P
2 ( ), . , .
imho. " , " - .
, , , . , .
.
, ( ) :
, , . , # .
, . . ...
MulticastDelegate , , . , , .
, , .
, , ...
this.btSomeButton.Click += (sender, args) { this.doFunc1(); this.doFunc2(); };
() .
. , , - , , , , .
, , . , , func1() func2() , , , , (, , ).
Source: https://habr.com/ru/post/1706269/More articles:Position the pointer over a handle when hovering over a user interface element in Silverlight - silverlightIronPython for unit testing with IronPython Studios - ironpythonlibrary for the server side (c / C ++) xmlrpc - c ++PHP mkdir (), chmod () and Windows - windowsSort WPF ListBox on button click? - sortingBookstore database design - databaseC ++ dll in C program - c ++Compiling VIM in Windows - vimThe symbolic confusion of JCL - jclHow to change this attenuation function to bounce less? - actionscript-3All Articles