I was just playing with delegate but I got confused about working of it. In below code
public delegate void HelloFunctionDelegate(string Message);
public static void Main()
{
//HelloFunctionDelegate del = new HelloFunctionDelegate(Hello1);
//del("hello from delegate");
Console.WriteLine("Hello World");
Hello(Hello1);
}
public static void Hello(HelloFunctionDelegate del)
{
del("This is it");//we did not create instance of delegate
}
public static void Hello1(string strMessage)
{
Console.WriteLine(strMessage);
}
Here It is working in both ways.we can pass method by creating new instance (commented code)and without creating new instance of delegate (HelloFunctionDelegate )? What is the difference between them?