It's a program, which is calculating Fibonacci numbers, using yield return(.net framework 4.6,C# 6.0).
C#
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:
using System;using System.Collections.Generic;using System.Linq;namespaceIEnumerable_interf{classProgram{staticvoidMain(string[]args){foreach(var item in Fib().Skip(0).Take(20)){
Console.WriteLine(item);}
Console.Read();}staticIEnumerable<int>Fib(){intcurrent=0;intnext=1;while(true){yieldreturncurrent;inttemp= current;current=next;next=temp+current;}}}}
Also we can skip some elements.
We can't use the ref and out keywords for the Iterator methods, which include a yield return or yield break statement.