0

I have a list that contains further sub lists and i have objects stored in the sub list. I want to generate all possible combinations of all elements.

e.g. we have a list that contains two list L1,L2 and all have different objects stored in the for example L1 contains {obj1,obj2} L2 contains {obj3,obj4}

then the result should come in the form of

{obj1,obj3}
{obj1,obj4}
{obj2,obj3}
{obj2,obj4}

all lists are being generated dynamically. so the solution should be generic irrespective of count of elements in main list and sub list

  • This is a request for a Cartesian product, which is a duplicate of (http://stackoverflow.com/questions/1741364/efficient-cartesian-product-algorithm) and (http://stackoverflow.com/questions/2419370/how-can-i-compute-a-cartesian-product-iteratively), if not others. – david.pfx Apr 04 '14 at 13:48

1 Answers1

0

L1.SelectMany(l1 => L2.Select(l2 => Tuple.Create(l1, l2))).ToList();

Gregoire
  • 24,219
  • 6
  • 46
  • 73