When to use static methods?

This is a question that hanuts me since I installed Resharper recently. Resharper keeps suggesting that the method can be static. I can see that it can be static. The method does not depend on any properties or methods of the class. But does that mean it should change to static?

I wasn’t sure, so I asked google. Often, I think google is like a wizard or rabbi. I ask a question, and it answers. Anyway, there were people who were curios and thought about it.

Kristofer Gafvert says,

Does this method belong to an object, or the class itself?
A method belongs to an object, if it modifies the state of the object. If
the method does not modify a specific object, it can most likely be static.

I really agree. if the method does not modifies the state of the object, it just belongs to the class, not the object. What do you think?

Please have a look on this discussion.

When to use static methods?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s