Guest User

Untitled

a guest
Feb 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace FibonacciTest
  6. {
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. foreach (var i in FibonacciGeneratorTwo.Fibonacci().Take(10))
  12. {
  13. Console.WriteLine(i);
  14. }
  15. }
  16. }
  17.  
  18. internal static class FibonacciGeneratorTwo
  19. {
  20. public static IEnumerable<int> Fibonacci()
  21. {
  22. int current = 1, next = 1;
  23. while (true)
  24. {
  25. yield return current;
  26. next = current + (current = next);
  27. }
  28. }
  29. }
  30. }
Add Comment
Please, Sign In to add comment