c# - How do i pass in a delegate as a parameter -


i want pass in void or int/string/bool(which returns value) dynamically so.

delay(myvoid);//i wont execute delay here, after delay execute the param/void so... public static void myvoid() {     messagebox.show("the void has started!"); } public async task myasyncmethod(void v) {     await task.delay(2000);     v() } 

ps, have tried using delegates doesn't let use parameter.

use action delegate execute method returns void:

public async task myasyncmethod(action v) {     await task.delay(2000);     v(); } 

or func<t> method returns value

public async task myasyncmethod(func<int> v) {     await task.delay(2000);     int result = v(); } 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -