【发布时间】:2015-08-25 05:56:47
【问题描述】:
我知道这是一个非常愚蠢的问题,但这可能吗?
说我有这门课
Class A
{
string propertyA;
Public A()
{
// do something here
}
}
然后这个:
Class B
{
A classA;
string propertyB;
}
通常我会这样做:
B classB = new B();
A classA = new A();
B.classA = classA;
有没有办法实现这样的目标:
Class A
{
string propertyA;
Public A()
{
// get or set B's properties
// but the problem is this class doesnt have a Parent property
}
}
【问题讨论】:
-
你不能使用
B.classA = classA;,因为类成员默认是private! -
我不确定您实际上要解决什么问题,但这个“解决方案”不是您所需要的。
-
您能详细说明为什么您不能或不会将 A 中的引用存储回 B 吗?
标签: .net class inheritance