I know that people have asked this question before, but the scenario was too specific, and I am confused about the basic principles.
I have two basic versions of C #, one of which works, and the other does not. I would be very pleased if someone could explain why I get an error. An object reference is required for a non-static field, method or property in the second program.
Works:
namespace Experiments
{
class Test
{
public string myTest = "Gobbledigook";
public void Print()
{
Console.Write(myTest);
}
}
class Program
{
static void Main(string[] args)
{
Test newTest = new Test();
newTest.Print();
while (true)
;
}
}
}
Does not work:
namespace Experiments
{
class Test
{
public string myTest = "Gobbledigook";
public void Print()
{
Console.Write(myTest);
}
}
class Program
{
public Test newTest = new Test();
static void Main(string[] args)
{
newTest.Print();
while (true)
;
}
}
}
() Test() , , , , . , , Test(), ++, .
?