Static vs. non-static method

前端 未结 10 1035
执念已碎
执念已碎 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:19

    There should be a slight performance improvement if you declare the method static, because the compiler will emit a call IL instruction instead of callvirt.

    But like the others said, it should be static anyway, since it is not related to a specific instance

提交回复
热议问题