编辑:如下面的评论,你要找的是一个readonly变量:
class MyClass {
readonly int myInteger;
public MyClass() {
myInteger = 10; // works
}
public void DoSomething() {
myInteger = 5; // not allowed
}
}
Run Code Online (Sandbox Code Playgroud)
听起来你在谈论一个static变量,而不是一个变量constant.就这样做:
class MyClass {
static int myInteger;
public void DoSomething() {
myInteger = 5; // is now changed for all instances
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
78 次 |
| 最近记录: |