Using private static methods Instead of private methods In C# [duplicate]
When its recom开发者_运维技巧mended to use a private static method instead of a private [instance] method?
EDIT: i am looking for a good (or best practice) about that .i am wondering Is this technic used by microsoft or not?does anybody know something about that ? i coudnt find any blog ,article or sample source code that explains this topic.
any help would be highly appreciated.
Static
word in the beginning of the method declaration, basically is a sign of stateless, so what is happening inside is a pure action, or at least should be.
If you want to use private static
: use it like API functions of your class that just make some calculations/reports... and not change the actual state of the object, which basically is done by instance
methods.
This is an expected way of implementing, which doens't mean that is mandatory, but as it's expected, it will help other developers understand your code, and help understand code to you after a couple of years, when you will come back to your project and already have forgot everything.
Regards.
精彩评论