Will C# inline methods that are declared in interfaces?

∥☆過路亽.° 提交于 2019-12-05 10:56:53

If you call DoSomething directly then it will be a candidate for inlining (depending on whether the method meets the other inlining criteria relating to size etc).

If you call DoSomething via the interface then it will not be inlined. The indirection provided by the interface results in a virtual call requiring a vtable lookup so the JIT compiler is unable to inline it since the actual callsite is only resolved at runtime.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!