Is there a performance hit for creating Extension methods that operate off the type 'object'?

前端 未结 4 846
我在风中等你
我在风中等你 2020-12-03 07:03

I have a set of extension methods that I regularly use for various UI tasks. I typically define them to run off of type object, even though inside of them I\'m

4条回答
  •  孤街浪徒
    2020-12-03 07:46

    Compared to when you call ToString befor the call to FormatSomething not really (you're null check might take a few more ms but they also make the code more robust.

    Even if the compile time type of the object you're calling the method on was string it still would make a visible difference.

    Don't worry about performance until you have a performance issue. Until then worry about maintainability including readability. If you have a performance problem then use a profiler to find where it is.

提交回复
热议问题