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; 

more info here


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -