The difference between static and non-static methods: 1. Static methods can be called without a class instantiation, whereas non-static methods need to be instantiated before they are invoked; 2. Static methods can access only static members and methods, non-static methods are accessible; 3. Static methods cannot be marked as override, resulting in a derived class that cannot be overridden. but can be accessed; 4. Static members are initialized on first use. Non-static members are in the creation of objects, from the memory allocation of static is continuous, non-static in memory is discrete, so static methods and non-static methods, at the call speed, static method speed must be fast, because non-static methods need to instantiate, allocate memory, but static methods do not, However, this difference in speed can be ignored when using a static method, and when to use the instance method: 1. A method is independent of the instance object of his class and does not depend on the new instance, then it should be static 2. No need for object-oriented ideas to use static, such as animal-RUN, Because you may expand the cat run, dog run, this time you need to use a non-static method about thread safety: Static method Only one instance, when there is a static variable, for high concurrency, the concurrency of all the execution of the method, the value of the static variable will change, resulting in problems; Of course, concurrency is not safe with the method itself, and the shared resource has a relationship such as a variable, each thread to its operation, can change its value, multithreading (concurrency is actually multithreaded), operation it, its value is chaotic, there is a problem why use non-static method
This is I write a method, originally directly written static method, no other reason, because do not want to instantiate can be less one line of code, and did not think of static and non-static difference = =! Of course it is possible to write a non-static method;
Reason
1. Because the method requires repeated calls, each time the new one will cause memory overhead, the static method will always be in memory, do not need to re-new a piece of space to initialize the data;
2. Do not need to do oo;
3. The method does not rely on new content;
Compared to the classic static method, Dbhelp is basically a static method
The difference between static and non-static methods in C #