【发布时间】:2012-01-04 16:51:39
【问题描述】:
下面的例子,如何引用基类实例?
public class A
{
public string test;
public A()
{
B b = new B();
test = "I am A class of test.";
}
public void hello()
{
MessageBox.Show("I am A class of hello.");
}
class B
{
public B()
{
//Here...
//How can I get A class of test and call A class of hello method
//base.test or base.hello() are not working.
}
}
}
【问题讨论】:
-
你会怎么做呢?您在 B 类的实例中没有 A 类的实例。
-
如果这个例子在 Java 中,我可以使用 A.this.test 或 A.this.hello(),但是在 C# 中我该怎么做?除了传递 A 到 B 的引用?
标签: c#-2.0