邮很多种办法,比如在B定义一个A的实例属性private A _Parent; public A Parent () { set{_Parent=value;} get{return _Parent;} }在A中 public int D; B.Parent=this; B中使用D this.Parent.D和 Parent.D
B中使用D this.Parent.D或 _Parent.D
To access the top level variable in the nested classes architecture, must use Static to define the variables whole access by Sub Classes.
原來以為很簡單得一個問題,想不到卻沒有人能夠解決!
郁悶~~~~~
是CSDN沒有人還是我的問題太難啊? 這么基本得問題都解決不了!
protect子类就可以通过继承得到父类的变量,如果你喜欢public,static也可以
我需要在外面訪問啊!
我是在定義B類的一個唯獨屬性時需要訪問A中公有變量.
public A Parent ()
{
set{_Parent=value;}
get{return _Parent;}
}在A中
public int D;
B.Parent=this; B中使用D
this.Parent.D和 Parent.D
this.Parent.D或 _Parent.D