I declared a delegate:
public delegate void Del(string message);
Then i created a function that i want to add to the delegate:
public static void DelegateMethod(string message)
{
System.Console.WriteLine(message);
}
Now I add the function to the delegate and call it:
Del handler = new Del( DelegateMethod);
handler("Hello World");
Console.Read();
Why when I drop the static from the DelegateMethod do I get an error?
Why does the function I delegate have to be static?
Because you are writing this code inside a static method. Given the fact that you are using
Console.ReadI presume you have put this code inside thestatic void Mainmethod of your console application. If you wanted to drop thestatickeyword from the method you will need an instance of the class containing this method. Like this: