1, static classes can not include non-static members, such as non-static methods, constructors, non-static classes may include static members. If you do not follow this rule, the static class compiler will check for an error.
In short, all members in a static class must be static members, but static members are not necessarily in static classes.
2. Static classes cannot be instantiated, their members can be used directly, static members in non-static classes do not need to be instantiated, they can be used directly, and non-static members in non-static classes must be instantiated.
In a nutshell, a static member does not need to instantiate its class, not a static member must instantiate the class it resides in.
3, static member execution speed is fast, because it is compiled at the time of the compiler placed in the static zone (saving automatic global variables and static variables) of the contents of the rest of the total program life, and the ordinary class of non-static members need to instantiate, in the stack to save the reference address, the heap to save the instance object, To get the method, so the speed is slow.
Static member variables are loaded into the static area of the memory when the program starts, regardless of whether the methods or properties are used later
。 Even if no one is accessing the program, this part of the memory is still not released.
4. Static member variables are shared, which means that when an instance of a class modifies the static member variable, its modified value is the other
See all the examples.
5. Static methods and properties cannot access non-static fields and events in their containing types.
6. Static methods can only be overloaded, not overridden, because static methods do not belong to instance members of the class.
7. C # does not support static local variables (static variables are defined inside a method).
8, static class is sealed class (sealed), cannot be inherited. Its sealing is the function of self-protection, and conforms to the packaging idea of the three main ideas of programming.
9, the static member is equal to the global variable, the whole system exists in a unified area (static zone), is shared, such as static into Num=0, when the compilation of Num is already 1, a thread changed its value for 1,b thread to get the time num is 1.
The difference between static and non-static classes and static and non-static methods