No. The conditional operator is only valid for non-void expressions. The point is to evaluate one of two expressions, and for that to be the result.
Basically: write the if
statement. It's the idiomatic way of executing one action or another.
You could write an extension method like this:
// For demonstration purposes only. Please don't use in real life.
public static void Conditional(this bool result,
Action trueAction,
Action falseAction)
{
Action action = result ? trueAction : falseAction;
action();
}
Then:
(A == B).Conditional(FunctionA, FunctionB);
... but I'd strongly advise you not to.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…