Static variables. in NET work differently to global variables that compile to 开发者_JAVA技巧native languageslike C++ or Fortran? Why?
There is no semantic difference. A static field is just a fancy name for a global variable.
Global variables are usually accessible without any limitation. This is also the reason they are often considered evil as you cannot take any care of keeping other parts of your code from misusing then, and errors concerning this variable can be anywhere in your code.
The static variable (or field) in .net however does allow for a lot more protection. You can declare it private or protected to limit the code that can access or change it. This wil make debugging a lot easier becouse when an error occurs there are a lot less places in your code that can be responsible for it.
精彩评论