event.Invoke(args) vs event(args). Which is faster?

前端 未结 4 1322
南旧
南旧 2020-12-13 18:31

Which is faster; using event.Invoke(args), or just calling event(args). What\'s the difference? Is one faster or slower than the other; or is it ju

4条回答
  •  悲&欢浪女
    2020-12-13 19:37

    Writing someDelegate(...) is a compiler shorthand for someDelegate.Invoke(...).
    They both compile to the same IL—a callvirt instruction to that delegate type's Invoke method.

    The Invoke method is generated by the compiler for each concrete delegate type.

    By contrast, the DynamicInvoke method, defined on the base Delegate type, uses reflection to call the delegate and is slow.

提交回复
热议问题