如果永远不会发生收益回报,为null返回? [英] If yield return never occurs, is null returned?

查看:115
本文介绍了如果永远不会发生收益回报,为null返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该方法通过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返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆