Why can you not invoke extension methods directly?

后端 未结 4 955
离开以前
离开以前 2021-01-11 16:13

Can someone explain to me why in the following the 3rd invocation of DoSomething is invalid? ( Error message is \"The name \'DoSomething\' does not exist in the current cont

4条回答
  •  日久生厌
    2021-01-11 16:57

    Extension methods can be invoked like other static methods.

    Change it to A_Ext.DoSomething(this).

    If you're asking why it isn't implicitly invoked on this, the answer is that that's the way the spec was written. I would assume that the reason is that calling it without a qualifier would be too misleading.

提交回复
热议问题