kosnkov
kosnkov

Reputation: 5911

Return combined expression

Following example gives me an error

public Func<double> ReturnExpression(Func<double> a, Func<double> b)
        {
            return () => a * b;
        }

what is wrong with that ? If I know that a returns double, and b also, why I can't return new expression combined from results of a and b ?

Error I have : can't applay operand * to operands of type Func<double> and Func<double>

Upvotes: 0

Views: 34

Answers (1)

garryp
garryp

Reputation: 5766

a and b are functions. You need to do this:

public Func<double> ReturnExpression(Func<double> a, Func<double> b)
        {
            return () => a() * b();
        }

Syntax is invalid in the OP, but you get the idea.

Upvotes: 3

Related Questions