Why can\'t the keyword this
be used in a static method? I am wondering why C# defines this constraint. What benefits can be gained by this constraint?
[
The this
keyword can be used in a method marked as static
. The syntax is used to define extension methods in C#. This feature has been available since C# 3.0, released in 2007 (Wikipedia)
In the normal usage, this
refers to the instance, static
says that there is no instance (and therefore no this
). The fact that you can't use them together (aside from special exceptions like extension methods) follows naturally from understanding what this
and static
are, conceptually.