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

后端 未结 7 2151
梦谈多话
梦谈多话 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:47

    It is possible that since you don't have any methods that override the virtual method that the JIT is able to recognize this and use a direct call instead.

    For something like this it's generally better to test it out as you have done than try to guess what the performance will be. If you want to know more about how delegate invocation works, I suggest the excellent book "CLR Via C#" by Jeffrey Richter.

提交回复
热议问题