1

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'

6
  • 1
    show me errors .. It is very helpful if you state those errors. Also, show the signature of the UsingFactory, what does it accept as parameters ? Do ProofingA and ProofingB inherit from the same object ? Commented Sep 5, 2016 at 5:28
  • implement from the same interface Commented Sep 5, 2016 at 5:32
  • Also, what xxx.UsingFactory() takes as parameter? may be it does not take an Action without parameters? try x=>new ProfingA() Commented Sep 5, 2016 at 5:33
  • You have to explicitly cast your lambdas. See this question, or maybe these ones Commented Sep 5, 2016 at 5:35
  • @v11 And does your method accept Func<iThatComonInterface> or accepts what exactly ? Just an Action ? Commented Sep 5, 2016 at 5:39

1 Answer 1

2

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()
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.