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 operate on it, can change its value, multithreading (concurrency is actually multithreaded), operation it, its value confusion, there is a problem
The difference between static and non-static methods in C #