T
tshad
Here is a stripped down version of a delegate I am trying to get to work,
which is how an example program shows:
using System;
using System.Collections.Generic;
using System.Text;
namespace delegate4
{
class Program
{
delegate void Print(string s);
static void Main(string[] args)
{
// not anonymous - must have a method already set up to call
Print delegateVariable = new Print(realMethod);
<--------
delegateVariable("This is our non-anonymous delegate string");
}
public void realMethod(string myString)
{
Console.WriteLine(myString);
}
}
}
This gives me an error:
An object reference is required for the nonstatic field, method, or property
'delegate4.Program.realMethod(string)'
Why doesn't this work?
Thanks,
Tom
which is how an example program shows:
using System;
using System.Collections.Generic;
using System.Text;
namespace delegate4
{
class Program
{
delegate void Print(string s);
static void Main(string[] args)
{
// not anonymous - must have a method already set up to call
Print delegateVariable = new Print(realMethod);
<--------
delegateVariable("This is our non-anonymous delegate string");
}
public void realMethod(string myString)
{
Console.WriteLine(myString);
}
}
}
This gives me an error:
An object reference is required for the nonstatic field, method, or property
'delegate4.Program.realMethod(string)'
Why doesn't this work?
Thanks,
Tom