Static vs. non-static method

前端 未结 10 1101
执念已碎
执念已碎 2020-11-28 08:30

Suppose you have some method that could be made static, inside a non-static class.
For example:

private double power(double a, double b)
    {
        r         


        
10条回答
  •  时光取名叫无心
    2020-11-28 09:20

    The compiler will likely consider inlining this when it "JITs" the code as it's so short and if it does so then will likely be able to optimise out any reference to the unused this parameter. But you can't rely on any of that.

    You still have to make an object to call it on unless you make it static which has a much bigger overhead anyway if you don't need one for other reasons.

提交回复
热议问题