c# - Why am I able to use a method name instead of a delegate in this argument? -
public delegate void handlerdelegate(int val); public class process { public static void execute(handlerdelegate del) { del(5); } } class program { static void main(string[] args) { //handlerdelegate handler = task; first process.execute(task); // works - how? } public static void task(int val) { console.writeline(val); } } i understand delegate reference method, how able pass looks method name method accepts delegate argument?
its 1 of many ways of instantiating delegate
for example:
public delegate void del<t>(t item);//delegate public void notify(int i) { }//instance method different ways instantiate above delegate del method notify
del<int> d1 = new del<int>(notify); or
del<int> d2 = notify;
Comments
Post a Comment