In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:
using System;
using System.Collections.Generic;
using System.Linq;
namespace IEnumerable_interf
{
class Program
{
static void Main(string[] args)
{
foreach (var item in Fib().Skip(0).Take(20))
{
Console.WriteLine(item);
}
Console.Read();
}
static IEnumerable<int> Fib()
{
int current = 0;
int next = 1;
while (true)
{
yield return current;
int temp = current;
current = next;
next = temp + current;
}
}
}
}