using System;
using System.Linq;
using System.Linq.Expressions;
public class Test
{
public static void Main()
{
ParameterExpression p = Expression.Parameter(typeof(int));
BinaryExpression b1 = Expression.MakeBinary(ExpressionType.Multiply, p, Expression.Constant(5));//(10*5)
BinaryExpression b2 = Expression.MakeBinary(ExpressionType.Divide, Expression.Constant(9), Expression.Constant(4));//(9/4)
BinaryExpression b4 = Expression.MakeBinary(ExpressionType.Add, b1, b2);
var compiledLambda = (Func<int,int>)Expression.Lambda<Func<int,int>>(b4, new[] {p}).Compile();
Console.WriteLine(compiledLambda(10));
Console.WriteLine(compiledLambda(8));
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKdXNpbmcgU3lzdGVtLkxpbnEuRXhwcmVzc2lvbnM7CgoKcHVibGljIGNsYXNzIFRlc3QKewoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJewoKUGFyYW1ldGVyRXhwcmVzc2lvbiBwID0gRXhwcmVzc2lvbi5QYXJhbWV0ZXIodHlwZW9mKGludCkpOwpCaW5hcnlFeHByZXNzaW9uIGIxID0gRXhwcmVzc2lvbi5NYWtlQmluYXJ5KEV4cHJlc3Npb25UeXBlLk11bHRpcGx5LCBwLCBFeHByZXNzaW9uLkNvbnN0YW50KDUpKTsvLygxMCo1KQpCaW5hcnlFeHByZXNzaW9uIGIyID0gRXhwcmVzc2lvbi5NYWtlQmluYXJ5KEV4cHJlc3Npb25UeXBlLkRpdmlkZSwgRXhwcmVzc2lvbi5Db25zdGFudCg5KSwgRXhwcmVzc2lvbi5Db25zdGFudCg0KSk7Ly8oOS80KQpCaW5hcnlFeHByZXNzaW9uIGI0ID0gRXhwcmVzc2lvbi5NYWtlQmluYXJ5KEV4cHJlc3Npb25UeXBlLkFkZCwgYjEsIGIyKTsKdmFyIGNvbXBpbGVkTGFtYmRhID0gKEZ1bmM8aW50LGludD4pRXhwcmVzc2lvbi5MYW1iZGE8RnVuYzxpbnQsaW50Pj4oYjQsIG5ld1tdIHtwfSkuQ29tcGlsZSgpOwpDb25zb2xlLldyaXRlTGluZShjb21waWxlZExhbWJkYSgxMCkpOwpDb25zb2xlLldyaXRlTGluZShjb21waWxlZExhbWJkYSg4KSk7CgoKCX0KfQ==