I have next snippet:
public Action<Action<bool>> GetAction()
{
return m => MyMethod(123, "string", m);
}
private void MyMethod(int someInteger, string someString, Action<bool> boolAction)
{
// some work with int and string was done
boolAction(true);
}
Could you please explain me why this work? I see that Action<Action<bool>> need some void method with only one parameter of Action<bool>. So what is wrong here with two first arguments?
Also it’s not clear for me why we pass m into. How this lambda could be called in the boolAction(true). What will happen there?
Any advice on this will be helpfull.
No reason that it shouldn’t work. In line where lambda is created, C# is automatically infers which parameters your lambda will receive, from type of
GetActionreturn value. To understand this code it’s important that you see that you are not returningm, but you are returningTherefore,
mis of typeAction<bool>, and above expression is of typeAction<Action<bool>>, where inner Action is actuallym.I.e.
creates lambda expression which would correspond to method of this signature:
From this part we see that
misAction<bool>, and_no_nameisAction<Action<bool>>.In the end you would use this code somehow like this probably:
Effectively, our message box call delegate becomes the
mparameter.