Skip to content

Instantly share code, notes, and snippets.

@leonmaia
Last active October 11, 2015 15:28
Show Gist options
  • Save leonmaia/3880396 to your computer and use it in GitHub Desktop.
Save leonmaia/3880396 to your computer and use it in GitHub Desktop.
Yield - Example
public object Solve()
{
return Fibonnaci().Where(i => i % 2 == 0).Sum();
}
private static IEnumerable<int> Fibonnaci()
{
int a = 1, b = 2;
yield return a;
yield return b;
while (b < 4000000)
{
var auxiliar = b;
b += a;
a = auxiliar;
yield return b;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment