views:

114

answers:

3

As it is clear from question, if I convert a normal method to static what gains will I made?

+11  A: 

You will gain clarity, because static makes it clear that the method doesn’t depend on an object state. You will also facilitate reusability because static methods may be used in more contexts (i.e. when you don’t have an instance of the class).

In general, it’s not really a question of gain, it’s a question of semantics: does your method depend on the object state? If so, make it non-static. In all other cases, make it static.

Konrad Rudolph
+1 for "it’s a question of semantics"
TheVillageIdiot
I would say you also need to consider discoverability. When someone tries to learn your API via code completion (IntelliSense) it is sometimes easier to find member methods than static methods.
Hallgrim
A: 

Static function normally used for utility stuffs like ConverThisTypeToThatType(), and you can call them without having object of its class.

Ex: MessageBox.Show("Something");

here MessageBox is a Class and Show is static method in it, so we dont need to create object of MessageBox to call Show.

Prashant
+1  A: 

Apart from the semantic reasons mentioned above, static methods are generally faster (due to not having to create an object to call the method). They are subject to compile-time optimisations and as far as I recall, the CLR also performs some special optimisations on them.

Ian Kemp
Thanks @Ian good insight.
TheVillageIdiot
I'm choosing this as answer because it seems to give clue about my performance curiosity!
TheVillageIdiot