//a[i-1] * i;
paramExp1 = Expression.Parameter(typeof(string), "a");
paramExp2 = Expression.Parameter(typeof(int), "i");
constantExp = Expression.Constant(1);
BinaryExpression subExp = Expression.Subtract(paramExp2, constantExp);
;//调用字符串类型的参数paramExp1的ToCharArray方法或索引
mutiplyExp = Expression.Multiply(indexExp, paramExp2);
del = Expression.Lambda(mutiplyExp, paramExp1, paramExp2).Compile();
Console.WriteLine("Expression a[i-1] * i: " + del.DynamicInvoke("000", 1));
//如果可以的话,顺便说说怎么调用参数的方法
var paramExp1 = Expression.Parameter(typeof(string), "a"); var paramExp2 = Expression.Parameter(typeof(int), "i"); var constantExp = Expression.Constant(1); BinaryExpression subExp = Expression.Subtract(paramExp2, constantExp); var method = typeof(string).GetMethod("ToCharArray", new Type[0]); var callExpression = Expression.Call(paramExp1, method); var indexExp = NewArrayExpression.ArrayAccess(callExpression, subExp); var charToIntExp = Expression.Convert(indexExp, typeof(int)); var mutiplyExp = Expression.Multiply(charToIntExp, paramExp2); var del = Expression.Lambda(mutiplyExp, paramExp1, paramExp2).Compile(); Console.WriteLine("Expression a[i-1] * i: " + del.DynamicInvoke("000", 1));