首页 > 技术文章 > Lambda编写斐波那契数列

hont 2016-01-09 21:22 原文

还需要考虑溢出等问题,闲来无事写了写

Func<float, float, float> a = (arg1, arg2) => 0f;//init

var depth = 8;
a = (lastNumber, currentNumber) =>
    {
        if (depth <= 0) return currentNumber;
        depth--;
        return a(currentNumber, currentNumber + lastNumber);
    };

var result = a(0, 1);

推荐阅读