Reputation: 2234
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
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