looking for some solutions? You are welcome.

SOLVED: How to use expression to simulate mathematical expression?

user2155362:

below is my code fragment:

        ConstantExpression constant1 = Expression.Constant(5);
        ConstantExpression constant2 = Expression.Constant(5.3);
        Expression expr = Expression.Multiply(constant1, constant2);
        var compiled = Expression.Lambda<Func<double>>(expr).Compile();
        Console.WriteLine(compiled.Invoke());
        Console.WriteLine();

System raise exception at Expression expr = Expression.Multiply(constant1, constant2); the error message is there is no binary operator Multiply between “System.Int32” and “System.Double”. I change the multiply to add and div the error message is same.

How to use expression to simulate mathematical expression?

ps: I won't to use expression like ConstantExpression constant1 = Expression.Constant(5.0);



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent