Yield Return Many?

后端 未结 6 678
粉色の甜心
粉色の甜心 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:41

    No, there isn't, unless you completely replace every yield return with a single return statement using LINQ.

    For example:

    return someSet
        .Concat(someOtherSet.SelectMany(s => FindSingle(context, s));
    

提交回复
热议问题