Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace FibonacciTest
- {
- public class Program
- {
- public static void Main()
- {
- foreach (var i in FibonacciGeneratorTwo.Fibonacci().Take(10))
- {
- Console.WriteLine(i);
- }
- }
- }
- internal static class FibonacciGeneratorTwo
- {
- public static IEnumerable<int> Fibonacci()
- {
- int current = 1, next = 1;
- while (true)
- {
- yield return current;
- next = current + (current = next);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment