Why we use “this” in Extension Methods?

后端 未结 6 1307
遥遥无期
遥遥无期 2021-01-17 10:36

I want to ask why we use \"this\" keyword before the parameter in an extension method (C# Language)........... like this function :

    public static int ToI         


        
6条回答
  •  Happy的楠姐
    2021-01-17 11:14

    Because that's the way you tell the compiler that it's an extension method in the first place. Otherwise it's just a normal static method. I guess they chose this so they didn't have to come up with a new keyword and potentially break old code.

提交回复
热议问题