ReSharper complains when method can be static, but isn't

前端 未结 8 1362
萌比男神i
萌比男神i 2020-11-28 08:43

Why does ReSharper complain when a method can become static, but is not?

Is it because only one instance of a static method is created (on the type) and thus save on

8条回答
  •  Happy的楠姐
    2020-11-28 09:13

    From the FxCop documentation for the same warning (emphasis added):

    "Members that do not access instance data or call instance methods can be marked as static (Shared in Visual Basic). After you mark the methods as static, the compiler will emit non-virtual call sites to these members. Emitting non-virtual call sites will prevent a check at runtime for each call that ensures that the current object pointer is non-null. This can result in a measurable performance gain for performance-sensitive code. In some cases, the failure to access the current object instance represents a correctness issue."

提交回复
热议问题