Yield Return Many?

后端 未结 6 679
粉色の甜心
粉色の甜心 2020-12-03 04:08

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 subSelec         


        
6条回答
  •  一整个雨季
    2020-12-03 04:45

    Use Enumerable.SelectMany:

    return subSelectors.SelectMany(subselector => FindSingle(context, subSelector));
    

    This only works if you don't have any other yield return statements in your method.

提交回复
热议问题