using System;
using System.Linq;
using System.Linq.Expressions;
class Program {
static void Main(string[] args) {
Expression> isOddExpression = i => (i & 1) == 1;
ParameterExpression param = Expression.Parameter(typeof(int), "i");
Expression> isOdd =
Expression.Lambda>(
Expression.Equal(
Expression.And(
param,
Expression.Constant(1, typeof(int))),
Expression.Constant(1, typeof(int))),
new ParameterExpression[] { param });
Func isOddCompiledExpression = isOddExpression.Compile();
for (int i = 0; i < 10; i++) {
if (isOddCompiledExpression(i))
Console.WriteLine(i + " is odd");
else
Console.WriteLine(i + " is even");
}
}
}