I’m new to C#. I wonder why I get errors for this:
Error: For this method a Object-Reference is necessary (translated from the German Message). Any Ideas. Seems to be correct for me.
namespace DNS
{
public class Core
{
Dig dig;
public Core()
{
dig = new Dig();
}
public static void startTest()
{
dig.myServer = "10.10.10.10"; <------ ERROR
You are trying to access the instance
digfield in a static method which is not possible because you need an instance of an object in order to access instance members.One possibility is to make the
digfield static:Another possibility is to make the
startTestmethod and instance method:or yet another possibility is to create an instance of the
Coreobject in the static method:It will depend on your actual design requirements.