类定义中定义的变量static是类变量.
public MyClass
{
static int a; // class variable
}
Run Code Online (Sandbox Code Playgroud)
在函数(Method)中声明的变量是局部变量.
public class MyClass
{
static void Main()
{
string name; //local variable
}
}
Run Code Online (Sandbox Code Playgroud)
在类定义中声明的变量,当实例化类时,这些变量将是成员变量
public class MyClass
{
int a; // here they are local variable of class body.
int b;
}
//create instance of class
MyClass mc = new MyClass();
mc.a = 10; //these are member variables
mc.b = 11;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9135 次 |
| 最近记录: |