The so-called static and non-static, it is in the declaration of a more use of a "static."
So what is the difference between static and non-static?
1, for non-static members, including methods, fields, properties. Called when it needs to be invoked with an instantiated object. (new comes out.) )
For static members, calls are called using the class name.
This gives a question, can you use static classes to instantiate objects? The answer is, of course, negative, because the purpose of instantiating an object is to invoke an attribute, method, or field with an instantiated object. For a static class, it is called with the class name, so there is no need to instantiate an object for a static class. It is not possible to declare a static class object in VS.
2. In non-static functions, both static and non-static members can be used.
In static functions, only static methods, fields, and properties can be used.
3. In a static class, only static members are allowed, and instance members are not allowed to appear. (The so-called instance member, refers to the non-static member)
In non-static classes, you can allow static members to appear, and you can allow instance members to appear.
This brings up the problem that most of the classes are static classes. For example, we often use, Console.WriteLine (), Console.ReadLine () and so on. They are static classes that are called with the class name.
4. For non-static classes, members can be instantiated. Therefore, the class does not occupy memory space, and the instantiated object is space-occupying.
For static classes, classes are space-occupying. Because the memory space is differentiated as follows:
Therefore, the static class in the program is occupied space, there is a static storage area.
As a result, static classes are shared resources throughout the program project. Also, static classes are freed only after the program has finished.
The above is a small summary of static and non-static classes.
Reprint Please specify blog garden: http://www.cnblogs.com/gu-zhan/old Salty
C # The little things about static and non-static