use*_*010 0 c# inheritance constructor
编译器错误关键字"this"在当前上下文中不可用
delegate void CallBack(int i);
class A
{
public A(CallBack cb) { }
}
class B : A
{
public B() : base(new CallBack(this.f)){}
private void f(int i) { }
}
Run Code Online (Sandbox Code Playgroud)
为什么会出错?作为一种解决方案,我想在A()中提供无参数保护的ctor并且具有
class B : A
{
public B() : base() // inherit the new A() ctor
{
base.cb = new CallBack(this.f); //this is allowed here
}
//...
}
Run Code Online (Sandbox Code Playgroud)