Skip to content

Instantly share code, notes, and snippets.

@zHaytam
Created March 21, 2021 11:46
Show Gist options
  • Save zHaytam/6f9c7726bd9ab6022ece39506a08985e to your computer and use it in GitHub Desktop.
Save zHaytam/6f9c7726bd9ab6022ece39506a08985e to your computer and use it in GitHub Desktop.
Action simpleAction = () => Console.WriteLine("Simple Action");
Action<int> actionWithArg = (i) => Console.WriteLine("Simple Action " + i);
Func<Task> taskFunc = () => Task.CompletedTask;
Func<int, Task> taskWithArgFunc = (i) => Task.FromResult(i);
MulticastDelegate delegate1 = simpleAction;
MulticastDelegate delegate2 = actionWithArg;
MulticastDelegate delegate3 = taskFunc;
MulticastDelegate delegate4 = taskWithArgFunc;
Console.WriteLine(delegate1 is Action); // true
delegate1.GetInvocationList()[0].DynamicInvoke(); // Simple Action
delegate2.GetInvocationList()[0].DynamicInvoke(999); // Simple Action 999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment