In C# how do I define function which return function which returns nothing? Something like this:
class X
{
public Func<void> GetFuncReturningVoid() { ... }
}
A function returning nothing is an Action. Using a lambda expression, you could write this:
Action GetFuncReturningVoid() {
return () => Console.Writeline("my action");
}
And if you need to accept arguments...
Action<int, int> GetActionWithArguments() {
return (int x, int y) => Console.Writeline(x * y);
}
Or you can let the compiler infer the types:
Action<int, int> GetActionWithArguments() {
return (x, y) => Console.Writeline(x * y);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With