Why can you not invoke extension methods directly?

后端 未结 4 927
离开以前
离开以前 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 17:12

    DoSomething requires an instance of A to do anything, and without a qualifier, the compiler can't see which DoSomething you need to invoke. It doesn't know to check in A_Ext for your method unless you qualify it with this.

提交回复
热议问题