构造函数初始值设定项不允许我使用'this'

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)

Mar*_*eck 15

这是因为在基类构造函数运行之前,尚未创建"this".在你的第二个例子中,基础构造函数已经完成,现在"this"具有意义.