What is the yield keyword used for in C#?

后端 未结 17 1651
盖世英雄少女心
盖世英雄少女心 2020-11-22 05:26

In the How Can I Expose Only a Fragment of IList<> question one of the answers had the following code snippet:

IEnumerable FilteredList()
{
         


        
      
      
      
17条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 06:02

    If I understand this correctly, here's how I would phrase this from the perspective of the function implementing IEnumerable with yield.

    • Here's one.
    • Call again if you need another.
    • I'll remember what I already gave you.
    • I'll only know if I can give you another when you call again.

提交回复
热议问题