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
Post a Comment