How to call an extension method from own class without casting?

后端 未结 3 1436
死守一世寂寞
死守一世寂寞 2021-02-14 06:46

I\'m trying to call an extension method on my own class, but it fails to compile. Consider the following lines of code:

public interface IHelloWorld
{
}         


        
3条回答
  •  無奈伤痛
    2021-02-14 07:17

    this.HelloWorld(); works with no casting.

    Remember how Extension methods work:

    You use an object and compiler would know the type then it could resolve it to the extension method. If no object is used, then it would not be able to resolve it.

提交回复
热议问题