+ 1
Static 🤯🤯
When I should to use "static"? Either in a variable or class and methods. I know how it works but I don't know when I should use it.
1 Réponse
+ 4
A method is static if it does not depend on the object state. A variable in a class is static if it is shared among instances.
A static variable/function outside any class (in C) is assembly local. If the variable is not needed / the function not called outside the assembly unit, it is static.
By "is static" I mean is static in a formal sense and should be declared as such.