我有这段代码:
class MyClass
{
public class MySubClass
{
public int One { private set; public get; }
public int Two { private set; public get; }
public int Three { private set; public get; }
};
public MySubClass ObjectMySubClass { private set; public get; }
private void SetSomething()
{
ObjectMySubClass.One = 5; //can do that
}
}
我怎样才能使我的一、二和三变量可以在课堂外读取但只在 MyClass 中设置?
MyClass obj = new MyClass();
obj.ObjectMySubClass.One = 5; //can't
int value = obj.ObjectMySubClass.One; //can do that