关键字this在C#中的当前上下文中不可用

lij*_*050 0 c# xamarin.android xamarin

我有一个名为EventListener的接口,并且有一个名为Endpoint的类,它将eventlistener作为方法newInstance中的参数newInstance(boolean debug, EventListener eventListener) 现在在我的MainActivity类中,当我实现EventListener并创建一个endpoint实例时,它给出的错误称为"关键字,这在当前不可用"上下文"在C#中.

    public class MainActivity : Activity, IEventListener {
        Endpoint endpoint = Endpoint.newInstance(true, this);
    }
Run Code Online (Sandbox Code Playgroud)

令人惊讶的是,java中没有这个错误.有人可以解释有什么区别.

Ser*_*rvy 6

this初始化字段时无法使用.如果要使用,则需要在构造函数中初始化该字段this.