Using yield in C#

前端 未结 4 728
粉色の甜心
粉色の甜心 2021-02-02 11:09

I have a vague understanding of the yield keyword in c#, but I haven\'t yet seen the need to use it in my code. This probably comes from a lack of understanding of

4条回答
  •  囚心锁ツ
    2021-02-02 12:07

    Yield implements the pattern of lazy loading. I suggest to consider its usefulness from this perspective.

    For example. in the context of business software I'm working on, it could brings the advantage of lowering load on the database. You write code that pulls a variety of data from the database, but only that portion will be loaded which is really needed for a particular scenario. If a user doesn't go deeper in the UI, the respective data will not be loaded.

提交回复
热议问题