c# - Convert Func to Delegate -


this question has answer here:

i have following delegate defined:

public delegate object mydelegate(dynamic target); 

and have func<dynamic, object> object:

func<dynamic, object> myfunc 

how can convert myfunc mydelegate?

i have tried these instructions, none of them worked:

mydelegate mydeleg = myfunc; mydelegate mydeleg = (mydelegate) myfunc; mydelegate mydeleg = myfunc mydelegate; 

you can wrap existing delegate:

(mydelegate)(x => myfunc(x)) 

or equivalently:

mydelegate mydeleg = x => myfunc(x); 

this causes small performance loss on each invocation code simple.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -