Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler Error CS0120 [duplicate]

Tags:

c#

class

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..

namespace ConsoleApplication2
{
    public class Task
    {
        public string RusVer { get; set; } 
        public string Key { get; set; } 
        public string UserVer { get; set; }


        public void Check()
        {
            if (UserVer == Key)
                Console.WriteLine("Good");            
        }
    }

class Program
{
    static void Main(string[] args)
    {

        Task p1 = new Task();
        p1.RusVer = "Привет, Мир!";
        p1.Key = "Hello, World!";
        Console.WriteLine(p1.RusVer);
        Console.WriteLine("Translate it: ");
        p1.UserVer = Convert.ToString(Console.ReadLine());
        Console.WriteLine(p1.UserVer);

        Task.Check(); //errorCS0120

    }
}
}
like image 207
Eluvium Avatar asked Sep 21 '25 12:09

Eluvium


1 Answers

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

like image 86
empi Avatar answered Sep 23 '25 02:09

empi