Skip to content

It's a program, which is calculating Fibonacci numbers, using yield return(.net framework 4.6,C# 6.0).

Notifications You must be signed in to change notification settings

SatSargsyan/IEnumerable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

IEnumerable

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:

fib1

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;
            }
        }
    }
}

Also we can skip some elements.

fib

We can't use the ref and out keywords for the Iterator methods, which include a yield return or yield break statement.

About

It's a program, which is calculating Fibonacci numbers, using yield return(.net framework 4.6,C# 6.0).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages