Open utterances-bot opened 2 years ago
Don't limit yourself to lists....
IEnumerable<int> Fib(int a =1, int b=1)
{
while(true)
{
yield return a;
a = a + b;
yield return b;
b = b + a;
}
}
Fib().Take(10).Dump();
Nice idea! Have you used yield
for any other stuff?
C# Tip: use yield return to return one item at the time - Code4IT
Yield is a keyword that allows you to return an item at the time instead of creating a full list and returning it as a whole.
https://www.code4it.dev/csharptips/yield-return