Note that there are some explanatory texts on larger screens.

plurals
  1. POList all the possible combinations
    text
    copied!<p>I have a question related to the combination.</p> <p>I am actually developing a ecommerce site and I have a function to allow customer create product variant. </p> <p>For example: Black Pant 34W 30L, Black Pant 38W 32L, White Pant 34W 30l. Those are defined as product variants.</p> <p>Assume my pant has 3 options, and they are color, waist size and length.</p> <p>I now have 3 list.</p> <pre><code>ListA = {"black", "white", "red"} //For the color ListB = {30,32,34,36,38} //For the waist ListC ={28,30,32,34} //For the length </code></pre> <p>My question is how can I list all the possible combinations?</p> <p>My desired result should be look like {{black,30,28},{black,30,30},{black,30,32},{white,34 ,30}}</p> <p>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...</p> <p><strong>Problem Solved</strong></p> <p>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.</p> <p>For more information, you can read from these two links. <a href="http://www.interact-sw.co.uk/iangblog/2010/07/28/linq-cartesian-1" rel="nofollow">http://www.interact-sw.co.uk/iangblog/2010/07/28/linq-cartesian-1</a> <a href="http://blogs.msdn.com/b/ericlippert/archive/2010/06/28/computing-a-cartesian-product-with-linq.aspx" rel="nofollow">http://blogs.msdn.com/b/ericlippert/archive/2010/06/28/computing-a-cartesian-product-with-linq.aspx</a></p> <p>Thank you for all your help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload