Why keyword 'this' cannot be used in a static method?

后端 未结 13 1775
遇见更好的自我
遇见更好的自我 2020-12-16 14:13

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?

[

13条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 14:50

    this is an instance of the current object. With a static method, there is no current object, and as such, this doesn't exist. It's not really a constraint, but the entire point of a method being static.

提交回复
热议问题