C#迭代器实现斐波那契数列
static IEnumerable<int> Fibs(int count) { for (int i = 0,prevFib=1,curFib=1; i < count; i++) { yield return prevFib; int newFib = prevFib + curFib; prevFib = curFib; curFib = newFib; } }
static IEnumerable<int> Fibs(int count) { for (int i = 0,prevFib=1,curFib=1; i < count; i++) { yield return prevFib; int newFib = prevFib + curFib; prevFib = curFib; curFib = newFib; } }