Why are “static” and “this” needed for extension methods, and how is their memory allocated?

The only difference between a static and a non-static method is that a non-static method receives an implicit parameter – this. Extension methods are not called in the context of the object on which the method is declared, therefore there is no way to pass them the this reference, therefore they must be static.

You cannot use the keyword this inside an extension method, I hope this answers your third question. The this keyword in the parameter list is there just to indicate which type this method extends.

What is your question about memory allocation? An extension method is just like any other static method, only the call syntax is different.

Leave a Comment