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

Solution 1:

I find that comment very useful as it points out two important things:

  1. It makes me ask myself if the method in question should actually be part of the type or not. Since it doesn't use any instance data, you should at least consider if it could be moved to its own type. Is it an integral part of the type, or is it really a general purpose utility method?

  2. If it does make sense to keep the method on the specific type, there's a potential performance gain as the compiler will emit different code for a static method.

Solution 2:

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."

Solution 3:

Very good debate on that subject here (SO). I am in the camp of if-it-can-be-made-static-make-it-static. I believe this because of the notion of why one would have an instance method that does not use any instance data. Is it truly an instance method in that case or is it actually a class method?

Solution 4:

No (zero) instances of the class need to be created to use the method if it is declared as static... that saves cpu cycles necessary for construction processing, heap space, and cpu cycles by the Garbage collector in reclaiming the object from the heap...

Also, your question, as it it written

" ... only one instance of a static method is created (on the type)... "

implies that for an instance method, the code for the method is repeated for each instance of the class that is created. That is not true. No matter how many instances you create for any type, the code for the methods is loaded into memory only once. The object stored on the heap for each instance only stores the type's "State", (non-static fields & a few misc tracking variables).

Solution 5:

It's not a complaint, it's just advice.