类变量,成员变量和局部变量,全局变量之间的区别

阿卜杜勒·哈利克(Abdul Khaliq)

分类在`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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章