SelectMany Three Levels Deep

前端 未结 3 1722
甜味超标
甜味超标 2021-02-02 12:18

I can flatten the results of a child collection within a collection with SelectMany:

 // a list of Foos, a Foo contains a List of Bars
 var source = new List<         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-02-02 12:43

           var q = source.SelectMany(foo => foo.Bar)
              .SelectMany(bar => bar.Widget,(bar,widget) => widget.WidgetId)
              .ToList();
    

    we can call this overload of SelectMany() with allow us to specify the projection using lambda experession

提交回复
热议问题