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

后端 未结 7 1655
温柔的废话
温柔的废话 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 07:05

    If You want to use non static function of class in static function.Create object of class in static function. For Eg

        Class ClsProgram(){
    public static void staticfunc(){
    ClsProgram Obj = new ClsPrograM()
    Obj.NonStaticFunc();
    }
    public void NonStaticFunc(){}
    }
    

提交回复
热议问题