Speeding up Reflection API with delegate in .NET/C#

前端 未结 5 1604
死守一世寂寞
死守一世寂寞 2021-01-02 16:08

This post has the comment if you need to call the method multiple times, use reflection once to find it, then assign it to a delegate, and then call the delegate.

5条回答
  •  长情又很酷
    2021-01-02 17:05

    Obviously it will work faster because of the reduced overheard caused by reflection. If you follow the tip, you won't go for reflection each time rather you will store reference in a delegate and hence you are reducing cost by not redoing the reflection. So yes, it will act like caching i guess once you are storing reference in a delegate in a sense that you won't have to go to reflection again

提交回复
热议问题