Function like bool decide(bool x) can be passed in method as parameter as functor as:
foo(Func<bool,bool> lambda)
We can have lambda expression like ()=>{int x=8; x=x+2;} that does not take anything and return anything. Lets say I want to pass such function as parameter to another method bar then how can it be done?
This is Action, not Func. If you don't want to return value, then you must use Action.
For example:
Action<int> example1 = (int x) => Console.WriteLine("Write {0}", x);
example1.Invoke(1); // or example1(1);
Action example3 = () => Console.WriteLine("Done");
example3.Invoke(); // or example3();
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