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

后端 未结 13 1887
遇见更好的自我
遇见更好的自我 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:28

    'this' refers to an instance of a class. Static is initialized without instantiation and hence the static method cannot refer to an 'instance' that is not created.

提交回复
热议问题