Static classes are used when a class provides functionality that is not specific to any unique instance. Here are the features of static classes in C# 2.0.
•Static classes can not be instantiated.
•Static classes are sealed so they can not be inherited.
•Only static members are allowed.
•Static classes can only have static constructor to initialize static members.
Advantages :
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.
One of the biggest problems we VB developers migrating to C# face is understanding STATIC. Static constructors, static data, static member functions, static properties.
To a VB developer, “static” means a variable inside a function (method) whose value remains “live” between function calls, but which is invisible outside the function. In C#, there is no such concept, because it’s not necessary when you can define member fields instead.
No comments:
Post a Comment