这是更快;使用event.Invoke(参数),或者只调用事件(参数)。有什么不同?比另一个更快或更慢;或者是preference它只是一个问题?
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 just a matter of preference?
写 someDelegate(...)
是一个编译器速记 someDelegate。调用(...)
。
他们都编译为相同的IL— A callvirt
指令的委托类型的调用
方法
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.
相反, DynamicInvoke
方法的基础上定义的代理
键入,使用反射调用委托和是缓慢的。
By contrast, the DynamicInvoke
method, defined on the base Delegate
type, uses reflection to call the delegate and is slow.
上一篇:当要使用的呢?要使