I just play with Actionto extract lambda expressions.
I have a boolean variable, and based on its value, my lambda body should be different.
However, in this particular case, the difference is simply a call to another method that does not change the type of the return value. This is what I have:
Action<MyType> myLambda;
if (myBooleanCondition)
{
myLambda = x => x.ChangeBehavior();
}
else
{
myLambda = x => x.ChangeBehavior().ChangeSize();
}
Is it possible to reduce / combine two lambda definitions into one to make it more elegant?
This project uses C # 4.0, but if it has been simplified in newer versions, let me know.
source
share