mikawudi
2014-01-22 02:18:29 +08:00
Func<Func<int, int>, int, Func<int, int>, int, int> sum = (term, a, next, b) =>
{
Func<int, int, int> iter = null;
iter = (a1, result) =>
{
if (a1 > b)
return result;
else
return iter(next(a1), term(a1) + result);
};
return iter(a, 0);
};
int ss = sum((x) => { return x; }, 1, (i) => { return i + 1; }, 10);
C#版本.....简单来说是做累加,不过写的更泛用了....步长和每一次对累加值可以进行自定义....差不多这个意思?....写完才发现lambda表达式貌似不能递归自己....还要显示声明下再用引用来递归...好难受