public static List<int> DoGetFibonacci(int n)
{
int a = 1, b = 2, c = 0;
List<int> series = new List<int>();
series.Add(a);
series.Add(b);
while (series.Count < n)
{
c = a + b;
a = b;
b = c;
series.Add(c);
}
return series;
}
How it works:
The core of Fibonacci series is adding up previous two numbers a and b to form the next number c. Taking this as the base we build the logic and put it in a loop to iteratively generate the series.