Yield return in C#
kenneth-truyers.net
Yield return in C#
1–9 of 9 posts
Re: Yield return in C#
#2Re: Yield return in C#
#3Any questions are welcome!
Re: Yield return in C#
#4Re: Yield return in C#
#5Re: Yield return in C#
#6Any questions are welcome!
(Either way, I did not know C# had this feature, it looks very nice! Also, the article is very well written, thanks a lot!)
Re: Yield return in C#
#7Any questions are welcome!
Honest question: Is this just coroutines or am I missing something? (Either way, I did not know C# had this feature, it looks very nice! Also, the article is very well written, thanks a lot!)
Here's some more info (although outdated): https://en.wikipedia.org/wiki/Coroutine#Implementations_for_...
Thanks, glad you enjoyed it!
Re: Yield return in C#
#8Any questions are welcome!
Honest question: Is this just coroutines or am I missing something? (Either way, I did not know C# had this feature, it looks very nice! Also, the article is very well written, thanks a lot!)
It use a simple state machine. The async keyword is implemented with the same principle.
Re: Yield return in C#
#9I've always like the good old fibonacci sequence for this too, because it shows off some simple logic that we all know, but it touches on some non-intuitive aspects (like yields being anywhere, and infinitely long IEnumerables).
public IEnumerable Fib() {
yield return 1;
yield return 1;
int a = 1, b = 1;
while (true) {
b = a + b;
a = b - a;
yield return b;
}
}
Then the 500th fibonachi number is: Fib().Skip(499).Next()