[英]Private vs Public variables
namespace hi
{
class hithere
{
public int numberOne = 12;
public int numberTwo = 12;
static void yo()
{
public int numberThree = 12;
private int numberFour = 12;
}
}
}
有人可以告诉我此代码摘录中的变量numberOne,numberTwo,numberThree和numberFour之间的区别吗?
numberOne和numberTwo是该类的成员变量。 numberThree和numberFour是局部变量,范围为该函数。
除此之外,您不能为局部变量声明访问修饰符(私有/公共)。
numberOne和numberTwo是堆中的公共实例变量。 可以在具有hithere对象实例的对象内部直接访问它们。 numberThree和numberFour不能以这种方式访问,因为它们不是实例变量,并且封装在函数yo的范围内,并分别存储在其中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.