
Not so long ago, in a
C # vs R # article
: using var instead of explicitly indicating the type I tried to explain what the R # sentences are caused to use var everywhere in the code instead of specifying a specific type. This time I would like to tell another story about R # related to why class methods are sometimes worth declaring static. For those who are interested in an explanation under the cut.
As you know, static methods, properties, and other elements of classes are intended primarily for accessing them without instantiating a class. You can make a whole static class that will return, say, the results of mathematical functions (see Math). But there is another reason why it makes sense to make methods static, even if you do not plan to use them without instantiating the class.

Sometimes, ReSharper gives a suggestion to convert the existing usual method into a static one. For me, this offer once again became an interesting mystery, and after a clue, I got into the Internet. It turned out that it makes sense to make methods that for one reason or another do not operate on the data of the instantiated class static because the call of such methods is faster, which in turn can positively affect the overall performance of the application.
')
A similar proposal is made by the Microsoft Code Analysis tool, there is a
small article in msdn about this and this is what it says:
“Shared in Visual Basic”. After you mark the compiler, you will emit non-virtual call sites to these members. Calling the current object pointer is non-virtual. This can result in a measurable performance code. In some cases, it represents the correctness issue. ”
If to touch the essence, the static methods are marked by the compiler as having non-virtual
platforms of the call , which prevents with each method call checking that the pointer to the null method is not equal. In addition,
according to msdn, only one instance of the method will exist for all objects of the class, which will also increase performance.
Cases where class methods do not operate with its properties are quite rare, but if they exist, then it seems to make sense to make them static.
Surely, there is a reason for discussion and I would love to listen to other opinions.