c# - Are there any notable differences between calling an event handling using 'Invoke' and using a 'traditional method call'? -


an event handler can invoked either of following:

someeventhandler.invoke(this, new eventargs()); 

or

someeventhandler(this, new eventargs()); 

are there notable differences between 2 versions? perhaps in terms of performance?

they same. compiled same code. difference 2 invoke method allows (in c# 6) use null-conditional operator ?. check if handler initialized before invoke it. in first case, have following

if (someeventhandler != null)     someeventhandler(this, new eventars()); 

whereas invoke can

someeventhandler?.invoke(this, new eventargs()); 

i hope helps.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -