Static classes are used when a class provides functionality that is not specific to any unique instance, means there will be no instance created, but its functions, static variables etc can be used using the class name. Here are the features of static classes in C# 2.0.
- Static classes cannot be instantiated.
- Static classes are sealed so they cannot be inherited.
- Only static members are allowed.
- Static classes can only have static constructor to initialize static members.
Compiler makes sure that no instance of static class is created. In previous version of C#, the constructor has to be marked private to avoid this from happening.
Also compiler makes sure that no instance members are declared within a static class.
In case we make functions/instance variables static instead of making the class as static, then for each request, an instance of the class would be created, which would be unnecessary like if we just need to use the class for having some constant/static messages/variables etc which are not an object specific.