Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
What's your idea about making static functions integraded in a single class to use in ASP.NET pages? Is it good or bad?
Posted
Comments
Sergey Alexandrovich Kryukov 25-Mar-12 17:25pm    
Good or bad -- for what? :-)
--SA
senguptaamlan 25-Mar-12 17:30pm    
Depends upon Ur requirement...it will great if you can specify the requirement a bit clearer.
Sergey Alexandrovich Kryukov 25-Mar-12 17:34pm    
Exactly, but it needs some explanations for a beginner. I answered, please see...
--SA

1 solution

It depends on your purpose. They exist, so they are good for something.

First, you need to understand what are they. Please see my past answer:
What makes static methods accessible?[^].

One important application for static members is the singleton pattern, please see:
http://en.wikipedia.org/wiki/Singleton_pattern[^].

Here is the good C# implementation; you can figure out the purpose of static:
http://csharpindepth.com/Articles/General/Singleton.aspx[^].

Please see my article for a very advanced (and funny) application:
Wish You Were Here… Only Once[^].

Static methods are used not so often; and they should be used with care when they also use static fields with access from different threads. In my article referenced above, you can find some valuable criticism by Paulo Zemec provided to fix a mistake I made.

At the same time, there are many functions where using them as instance (non-static) once would be a mistake. If they don't access instance data and are instance methods, it's a certain performance leak. FxCop, for example, will report it as a mistake.

[EDIT]

Two more important uses of static methods:

Operator overloading: http://msdn.microsoft.com/en-us/library/aa288467%28v=vs.71%29.aspx[^].

Extension methods: http://msdn.microsoft.com/en-us/library/bb383977.aspx[^].

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900