Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As stated in the comments Eric Lippert has a blog post named <a href="http://ericlippert.com/2010/06/28/computing-a-cartesian-product-with-linq/" rel="nofollow">Computing a Cartesian Product with LINQ</a> that explains how to solve your problem. You need an extension method to compute the cartesian product:</p> <pre><code>public static IEnumerable&lt;IEnumerable&lt;T&gt;&gt; CartesianProduct&lt;T&gt;(this IEnumerable&lt;IEnumerable&lt;T&gt;&gt; sequences) { IEnumerable&lt;IEnumerable&lt;T&gt;&gt; result = new [] { Enumerable.Empty&lt;T&gt;() }; foreach (var sequence in sequences) { var localSequence = sequence; result = result.SelectMany( _ =&gt; localSequence, (seq, item) =&gt; seq.Concat(new[] { item }) ); } return result; } </code></pre> <p>Then you need a sequence of sequences to perform the product over. In your case you have both strings and integers in your sequences so the common base type <code>T</code> has to be <code>Object</code>.</p> <pre><code>var sequences = new[] { new Object[] { "black", "white", "red" }, new Object[] { 30, 32, 34, 36, 38 }, new Object[] { 28, 30, 32, 34 } }; </code></pre> <p>To compute the Cartesian product you simply invoke the extension method:</p> <pre><code>var result = sequences.CartesianProduct(); </code></pre> <p>When you enumerate the result it is computed on the fly (lazily). If you prefer to create a list of lists you need to call <code>ToList()</code> after <code>Concat</code> and also before returning <code>result</code> from the extension method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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