Compiler Error CS0120

前端 未结 2 758
天命终不由人
天命终不由人 2020-12-12 07:48

I\'m trying to understand concept \"class\" and write some easy program. But my function Check() is not correct. Please follow me to the right side..

namespa         


        
相关标签:
2条回答
  • 2020-12-12 07:55

    You're calling Check as if it was static method. It is instance method so it should called p1.Check().

    0 讨论(0)
  • 2020-12-12 08:12

    Compiler Error CS0120: An object reference is required for the nonstatic field, method, or property 'member'

    So In order to use a non-static field, method, or property, you must first create an object instance of a class

    You need to call it with the help of Task class object

    p1.Check();
    

    If you declared Check() method as static then you can call it as you are currently doing.

     public static void Check()
     {
        if (UserVer == Key)
            Console.WriteLine("Good");            
     }
    
    0 讨论(0)
提交回复
热议问题