Why need Static methods?

I use static methods when I need to get something that is relevant to that class but I don’t want to create an instance every time to get this information. With a static method you cannot access methods/properties/variables from the class. The only variables available are within the static method you are calling.

Typically Helper and Utility methods are good candidates. Often times as well, you may want to create Static as well as instance objects. Looking to the framework, there’s the File and the FileInfo, the Directory and directoryInfo. Similarly, check out the Data Access Application Block – all of the SqlHelper methods are static.

Leave a comment

Filed under C#

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s