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
}
}
}
You're calling Check as if it was static method. It is instance method so it should called p1.Check().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With