产量返回许多? [英] Yield Return Many?
本文介绍了产量返回许多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现自己的foreach ING在IEnumerables很多只是,这样我可以返回各自的结果。有没有一种方法来压缩这样的事情
I find myself foreach-ing over IEnumerables a lot just so that I can return each result. Is there a way to compress something like this
foreach (var subSelector in subSelectors)
{
foreach (var node in FindSingle(context, subSelector))
yield return node;
}
要取下内的foreach?
To remove the inner foreach?
推荐答案
没有,没有,除非你完全代替每个收益回报率
有一个使用LINQ回报
语句
No, there isn't, unless you completely replace every yield return
with a single return
statement using LINQ.
例如:
return someSet
.Concat(someOtherSet.SelectMany(s => FindSingle(context, s));
这篇关于产量返回许多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文