编译器错误CS0120 [英] Compiler Error CS0120

查看:67
本文介绍了编译器错误CS0120的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解类的概念,并编写一些简单的程序。但是我的函数Check()不正确。请跟随我到右侧。

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

    }
}
}


推荐答案

您正在调用 Check ,就好像它是静态方法一样。这是实例方法,因此应调用 p1.Check()

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

这篇关于编译器错误CS0120的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆