0

I have list of lists. For example:

  List<List<string>> bigList = new List<List<string>>();

        var l1 = new List<string>();
        l1.Add("a1");
        l1.Add("a2");
        l1.Add("a3");

        var l2 = new List<string>();
        l2.Add("b1");
        l2.Add("b2");

        var l3 = new List<string>();
        l3.Add("c1");
        l3.Add("c2");

        bigList.Add(l1);
        bigList.Add(l2);
        bigList.Add(l3);

I need to create new list of lists, that will have 12 elements in my example (3*2*2). I need all combinations.

Result should be like this:

            //a1,b1,c1
            //a1,b1,c2
            //a1,b2,c1
            //a1,b2,c2    
            //a2,b1,c1
            //a2,b1,c2
            //a2,b2,c1
            //a2,b2,c2
            //a3,b1,c1
            //a3,b1,c2
            //a3,b2,c1
            //a3,b2,c2

Off course should work for any list of lists. Not just for this example. I realy have problem to write this algorithm. Thanks for help.

Raskolnikov
  • 3,791
  • 9
  • 43
  • 88
  • This not duplicate. In may case don't know how many list of lists I have. In example is 3 but it can be 15 lists. – Raskolnikov Aug 20 '15 at 10:43
  • @user2451446 Come on. At least try to read the post. (See the Eric Lippert's blog linked in his answer) – L.B Aug 20 '15 at 10:56

0 Answers0