I have a question related to the combination.
I am actually developing a ecommerce site and I have a function to allow customer create product variant.
For example: Black Pant 34W 30L, Black Pant 38W 32L, White Pant 34W 30l. Those are defined as product variants.
Assume my pant has 3 options, and they are color, waist size and length.
I now have 3 list.
ListA = {"black", "white", "red"} //For the color
ListB = {30,32,34,36,38} //For the waist
ListC ={28,30,32,34} //For the length
My question is how can I list all the possible combinations?
My desired result should be look like {{black,30,28},{black,30,30},{black,30,32},{white,34 ,30}}
P.S. The tricky part is that I don't know how many options customer will assign to this product. The count of the option might be just 1, which is the easiest; it could be more than 3...
Problem Solved
Since we don't know how many options we will have. Therefore, we don't know how many for loop we are going to use. In other word, it turns to a typical Cartesian Products.
For more information, you can read from these two links. http://www.interact-sw.co.uk/iangblog/2010/07/28/linq-cartesian-1 http://blogs.msdn.com/b/ericlippert/archive/2010/06/28/computing-a-cartesian-product-with-linq.aspx
Thank you for all your help!