Skip to content

Instantly share code, notes, and snippets.

@IneonInoodle
Created September 11, 2018 08:36
Show Gist options
  • Save IneonInoodle/f59d55011f894b34ff03238487d2d449 to your computer and use it in GitHub Desktop.
Save IneonInoodle/f59d55011f894b34ff03238487d2d449 to your computer and use it in GitHub Desktop.
static IEnumberable<int> GenerateFibonacciNumbers(int n)
{
List<int> myList = new List<int>();
for (int i = 0, j = 0, k = 1; i < n; i++)
{
yield return j;
int temp = j + k;
j = k;
k = temp;
}
return myList;
}
public static void Main(String[] args)
{
foreach (int x in GenerateFibonacciNumbers(5))
{
Console.WriteLine(x);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment