问题描述
该方法通过yield return语句返回的IEnumerable
The method returns IEnumerable via a yield return statement.
如果从未出现yield语句(它的内部条件逻辑),将方法返回null,或者将它0的计数返回一个可枚举?
If the yield statement never occurs (it's inside conditional logic), will the method return null, or will it return an Enumerable with a count of 0?
推荐答案
一个有效的IEnumerable当你遍历它不产生价值。
A valid IEnumerable that produces no values when you iterate through it.
试想一下:您可以将IEnumerable的发生器存储在一个变量 - 代码本身当你真正遍历这些结果只是得到执行。你怎么可以,如果你有执行的代码空
?或者,你是怎么知道的功能,不运行它不会产生任何东西。
Just think of it: You can store the IEnumerable generator in a variable - the code itself just gets executed when you actually iterate through the results. How could you execute the code if you had null
? Or how did you know the function doesn't yield anything without running it.
这篇关于如果永远不会发生收益回报,为null返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!