What is the purpose/advantage of using yield return iterators in C#?

前端 未结 10 1849
独厮守ぢ
独厮守ぢ 2020-12-04 06:43

All of the examples I\'ve seen of using yield return x; inside a C# method could be done in the same way by just returning the whole list. In those cases, is th

10条回答
  •  暖寄归人
    2020-12-04 07:18

    If the entire list is gigantic, it might eat a lot of memory just to sit around, whereas with the yield you only play with what you need, when you need it, regardless of how many items there are.

提交回复
热议问题