The Yield Statement Cannot Be Used Inside an Anonymous Method or Lambda Expression

I thought I was being pretty cool with this code:

IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator( ) {
  Action<UnbalancedBinaryTree> yielder = null;
  yielder = t => {
    if (!t.IsEmpty)
      yield return t.Value;

But as it turns out (and I think I knew before, but had forgotten), C# doesn’t accept this. Not in 3.0 at least, and I think not in 4.0 either. Need to test. Meanwhile – why? Hm…

Sorry, this blog does not support comments.

I used various blog hosting services since this blog was established in 2005, but unfortunately they turned out to be unreliable in the long term and comment threads were lost in unavoidable transitions. At this time I don't want to enable third-party services for comments since it has become obvious in recent years that these providers invariably monetize information about their visitors and users.

Please use the links in the page footer to get in touch with me. I'm available for conversations on Keybase, Matrix, Mastodon or Twitter, as well as via email.