I want to ask why we use “this” keyword before the parameter in an extension method (C# Language)………..
like this function :
public static int ToInt(this string number)
{
return Int32.Parse(number);
}
I know that we have to use it but I don’t know why.
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
thisso they didn’t have to come up with a new keyword and potentially break old code.