A static class cannot be instantiated, and can contain only static members. Hence, the calls for a static class are as: MyStaticClass.MyMethod(...) or MyStaticClass.MyConstant.
A non static class can be instantiated and may contain non-static members (instance constructors, destructor, indexers). A non-static member of a non-static class is callable only through an object:
MyNonStaticClass x = new MyNonStaticClass(...);
x.MyNonStaticMethod(...);
Static classes and members are used to create data and methods that can be accessed without creating an instance (using the new keyword, they cannot have a constructor) of the class.
Static classes can be declared when there is no dependence on the its own object identity, so a static class must contain only static members.
This classes are loaded by the CLR when the program or namespace containing the class is loaded.
A static class is just like a global variable: you can use it anywhere in your code without instantiating them.
For example: ClassName. After the dot operator, you can use any property or function of it.
public class ClassName {}
But if you have non-static class then you need to create an instance of this class.
For example:
http://www.javaworld.com/javaworld/javaqa/1999-08/01-qa-static2.html - very good article on this. This is for Java. But i think concept should should same in C# too.
A static class cannot be instantiated, and can contain only static members. Hence, the calls for a static class are as:
MyStaticClass.MyMethod(...)
orMyStaticClass.MyConstant
.A non static class can be instantiated and may contain non-static members (instance constructors, destructor, indexers). A non-static member of a non-static class is callable only through an object:
You can't instantiate (create objects of) a static class. And it can only contain static members.
Example: System.Math
Static classes and members are used to create data and methods that can be accessed without creating an instance (using the
new
keyword, they cannot have a constructor) of the class.Static classes can be declared when there is no dependence on the its own object identity, so a static class must contain only static members.
This classes are loaded by the CLR when the program or namespace containing the class is loaded.
They are also sealed, cannot be inherited from.
A static class is just like a global variable: you can use it anywhere in your code without instantiating them. For example: ClassName. After the dot operator, you can use any property or function of it.
But if you have non-static class then you need to create an instance of this class. For example:
Static class can contain static members only.
Static member can be used without instantiating a class first.