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
For info, the significance of this
as a contextual-keyword here is largely that it avoids introducing a new keyword. Whenever you introduce a new keyword you risk breaking code that would have used it as a variable / type name. this
has a few useful features:
This means that no existing code will be broken.
Beyond the choice of this
as the keyword, it is just a convenient syntax for the compiler, and more convenient than adding [Extension]
manually. Without either, it would just be a static method, without any special behaviour.