there are classes

public class B{ } public class A{ public List<B> ListB = new List<B>(); } 

there is a list of classes List<A> ListA = new List<A>();

how to use Linq methods to combine all ListB from ListA into one array or sheet, or any other IEnumerable<B> collection

    1 answer 1

    Use the SelectMany function

     var listsB = ListA.SelectMany(x=>x.ListB); 

    Or its query syntax

     var listsB = from a in ListA from b in a.ListB select b; 
    • Still a code sample ... - VladD
    • Thank. Apparently missed this method. I will confirm in 11 minutes. - Dmitry Chistik
    • 3
      @VladD, added :-) I thought, while I would look for the link to help someone find the thread :-) so he quickly flopped the answer and went for more information :) - Grundy