分类在`Class变量,Member变量,Local变量和Global变量之间?
类定义中定义为静态的变量是类变量。
public MyClass
{
static int a; // class variable
}
在函数(方法)中声明的变量是局部变量。
public class MyClass
{
static void Main()
{
string name; //local variable
}
}
在类定义中声明的变量,当实例化类时,这些变量将成为成员变量
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;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句