fork download
  1. using System;
  2. using System.Linq;
  3. using System.Linq.Expressions;
  4.  
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10.  
  11. ParameterExpression p = Expression.Parameter(typeof(int));
  12. BinaryExpression b1 = Expression.MakeBinary(ExpressionType.Multiply, p, Expression.Constant(5));//(10*5)
  13. BinaryExpression b2 = Expression.MakeBinary(ExpressionType.Divide, Expression.Constant(9), Expression.Constant(4));//(9/4)
  14. BinaryExpression b4 = Expression.MakeBinary(ExpressionType.Add, b1, b2);
  15. var compiledLambda = (Func<int,int>)Expression.Lambda<Func<int,int>>(b4, new[] {p}).Compile();
  16. Console.WriteLine(compiledLambda(10));
  17. Console.WriteLine(compiledLambda(8));
  18.  
  19.  
  20. }
  21. }
Success #stdin #stdout 0.04s 31696KB
stdin
Standard input is empty
stdout
52
42