v11 v11 - 10 months ago 65
C# Question

Using condition expression to choose lambda expression

I want to use condition expression to choose lambda expression, like that:

hasProofing? ( ()=>new ProofingA() ) : ( () => new ProofingB() )

But, it show me errors. So, if I want to do this thing, How should I do.

Error Detail:

no implicit conversion between 'lambda expression' and 'lambda


You need to explicitly cast at least one of the lambdas. For example, if it's just a Action, then you could use the following:

    hasProofing ? (Action)(() => new ProofingA()) : () => new ProofingB()