class Student
{
private string _name;
public int Age = 0; public static void Test()
{
Student stu = new Student();
stu._name = "dd";
stu.Age = 20;
}
}
如图,虽然Static修饰的方法不属于类本身,但是还是在private(本类)范围内,所以可以访问到类的私有变量。
2023-12-10 21:32:33
class Student
{
private string _name;
public int Age = 0; public static void Test()
{
Student stu = new Student();
stu._name = "dd";
stu.Age = 20;
}
}
如图,虽然Static修饰的方法不属于类本身,但是还是在private(本类)范围内,所以可以访问到类的私有变量。