开发者

How works statics variables in .Net and C++?

Static variables. in NET work differently to global variables that compile to 开发者_JAVA技巧native languages​​like 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜