问题描述
限时送ChatGPT账号..使用静态修饰符声明一个静态成员,属于键入本身而不是特定的对象.
Use the static modifier to declare a static member, which belongs to the type itself rather than to a specific object.
???
当我定义一个变量 public int abc
时,我遇到了这个静态关键字.当这个变量的值在while
的括号内,或if
的括号内,或方法的括号内发生变化时,这些变化是无效的,没有反映, 括号外不知道.所以只是一个命中试验.我将变量设为静态并解决了所有问题.
My encounter with this static keyword occurred when I defined a variable public int abc
. When the value of this variable changed withing the brackets of while
, or within the brackets of if
, or within the brackets of methods, these changes were not valid, were not reflected, were not know outside the brackets. So just a hit trial. I made the variable static and all problems solved.
但是为什么??
推荐答案
静态成员和非静态成员(不是变量)的区别在于,静态成员在程序的整个运行时是唯一的(即有只有一个静态成员实例),而非静态成员与对象实例相关联(即,对应对象的每个实例都有一个成员实例).这是定义所说的多一点.
The difference between a static and a non-static member (not variable) is that a static member is unique over the whole runtime of a program (i.e. there is only one static member instance) whereas a non-static member is associated with an object instance (i.e. there is a member instance for each instance of the corresponding object). This is in a bit more words what the definition says.
这一切如何适用于您所写的未反映的更改,我不太确定 - 也许您应该发布相应的代码.
How this all applies to what you wrote in regard to changes not reflected im not too sure - maybe you should post the corresponding code.
这篇关于C# static - MSDN 上的定义是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论