Possible Duplicate:
What is the use of a static class
What are the benefits of declaring a static class?
public static class MyStaticClass
{
}
Are there any other than "it can't be instantiated"?
Why else would you want a static class, for what reasons should a class be static?
Is "any class should be declared as static unless it's meant to be instantiated" a good rule of thumb?
If a class has the static modifier then:
The first point is the most important though, IMO. You're communicating intent to both the compiler and other developers.
Static classes are useful as containers for utility functions and constants. If the class does not represent an object and is used only for this purpose then it makes sense to declare it as static.
Static classes and class members are used to create data and functions that can be accessed without creating an instance of the class. Static class members can be used to separate data and behavior that is independent of any object identity: the data and functions do not change regardless of what happens to the object. Static classes can be used when there is no data or behavior in the class that depends on object identity.
Taken from MSDN directly. It explains it much better than I can. The key fact here is that the object persists throughout the life.
Extention methods also have to be written in static classes. I tend to use these for string extentions, or collection extentions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With