Some help understanding “yield”

前端 未结 8 1178
挽巷
挽巷 2020-11-30 01:41

In my everlasting quest to suck less I\'m trying to understand the \"yield\" statement, but I keep encountering the same error.

The body of [someMetho

8条回答
  •  佛祖请我去吃肉
    2020-11-30 02:14

    It's a tricky topic. In a nutshell, it's an easy way of implementing IEnumerable and its friends. The compiler builds you a state machine, transforming parameters and local variables into instance variables in a new class. Complicated stuff.

    I have a few resources on this:

    • Chapter 6 of C# in Depth (free download from that page)
    • Iterators, iterator blocks and data pipelines (article)
    • Iterator block implementation details (article)

提交回复
热议问题