Is 'yield return' slower than “old school” return?

后端 未结 5 1509
滥情空心
滥情空心 2020-12-19 10:01

I\'m doing some tests about yield return perfomance, and I found that it is slower than normal return.

I tested value variables (int, double, etc.) and some referenc

5条回答
  •  轮回少年
    2020-12-19 10:37

    For one, it's a convenience feature. Two, it lets you do lazy return, which means that it's only evaluated when the value's fetched. That can be invaluable in stuff like a DB query, or just a collection you don't want to completely iterate over. Three, it can be faster in some scenarios. Four, what was the difference? Probably tiny, so micro optimization.

提交回复
热议问题