using System; using System.Linq.Expressions; public class Test { static T add(T a, T b) { var p0 = Expression.Parameter(typeof(T),"a"); var p1 = Expression.Parameter(typeof(T),"b"); var ae = Expression.Add(p0, p1); var f = (Func)Expression.Lambda(ae, p0, p1).Compile(); return f(a, b); } public static void Main() { int a = 4, b = 6; double x = 2.3, y = 5.2; Console.WriteLine("Sum of two ints = {0}", add(a, b)); Console.WriteLine("Sum of two doubles = {0}", add(x, y)); } }