v11
v11

Reputation: 2234

Using condition expression to choose lambda expression

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

xxxx.UsingFactory(
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 expression'

Upvotes: 1

Views: 193

Answers (1)

grovesNL
grovesNL

Reputation: 6075

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:

xxxx.UsingFactory(
    hasProofing ? (Action)(() => new ProofingA()) : () => new ProofingB()
);

Upvotes: 2

Related Questions