Why can't you use the keyword 'this' in a static method in .Net?

后端 未结 7 1607
温柔的废话
温柔的废话 2020-11-27 06:46

I\'m trying to use the this keyword in a static method, but the compiler won\'t allow me to use it.

Why not?

7条回答
  •  無奈伤痛
    2020-11-27 06:53

    For OP's question, refer to the accepted answer. This answer is for the ones who're looking for a fast one liner to use in static methods.

    If the class is a form, and it's open (you need the name of the form as well), this can be called within a static method;

    Application.OpenForms["MainForm"];
    

提交回复
热议问题