开发者

Using private static methods Instead of private methods In C# [duplicate]

This question already has answers here: What is better? Static methods OR Instance methods (7 answers) Closed 9 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜