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 -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -