C# static

编程入门 行业动态 更新时间:2024-10-25 22:24:54
本文介绍了C# static - MSDN 上的定义是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-28 06:39:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1169662.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:static

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!