C#: Virtual Function invocation is even faster than a delegate invocation?

后端 未结 7 2297
梦谈多话
梦谈多话 2021-02-05 13:02

It just happens to me about one code design question. Say, I have one \"template\" method that invokes some functions that may \"alter\". A intuitive design is to follow \"Templ

7条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-05 13:43

    I doubt it accounts for all of your difference, but one thing off the top of my head that may account for some of the difference is that virtual method dispatch already has the this pointer ready to go. When calling through a delegate the this pointer has to be fetched from the delegate.

    Note that according to this blog article the difference was even greater in .NET v1.x.

提交回复
热议问题