Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you're looking to perform the <a href="http://blogs.msdn.com/b/ericlippert/archive/2010/06/28/computing-a-cartesian-product-with-linq.aspx" rel="nofollow">cartesian product</a> of each of your lists and get the distinct tuples (each tuple containing only distinct values).</p> <p>This algorithm isn't terribly efficient; it's going to generate a number of sets equal to the product of the lengths of all your lists and compare these sets to get the final distinct result. You would need to make some minor modifications to make it case-insensitive, but you didn't say if that was required.</p> <pre><code>Dictionary&lt;string, List&lt;string&gt;&gt; Data = new Dictionary&lt;string, List&lt;string&gt;&gt;() { {"BU1", new List&lt;string&gt;(){"ALL", "BU"}}, {"CON1", new List&lt;string&gt;(){"ALL", "EMP", "CONF", "CON1"}}, {"SS1", new List&lt;string&gt;(){"ALL", "EMP", "SS"}}, }; IEnumerable&lt;IEnumerable&lt;string&gt;&gt; Empty = Enumerable.Repeat(Enumerable.Empty&lt;string&gt;(), 1); Data.Aggregate(Empty, (accumulator, kvp) =&gt; from a in accumulator from i in kvp.Value select a.Concat(Enumerable.Repeat(i, 1))) .Select(set =&gt; new HashSet&lt;string&gt;(set)) .Distinct(HashSet&lt;string&gt;.CreateSetComparer()); </code></pre> <p>This produces the following output sets:</p> <pre><code>HashSet&lt;String&gt; (1 item) ALL HashSet&lt;String&gt; (2 items) ALL EMP HashSet&lt;String&gt; (2 items) ALL SS HashSet&lt;String&gt; (3 items) ALL EMP SS HashSet&lt;String&gt; (2 items) ALL CONF HashSet&lt;String&gt; (3 items) ALL CONF EMP HashSet&lt;String&gt; (3 items) ALL CONF SS HashSet&lt;String&gt; (2 items) ALL CON1 HashSet&lt;String&gt; (3 items) ALL CON1 EMP HashSet&lt;String&gt; (3 items) ALL CON1 SS HashSet&lt;String&gt; (2 items) BU ALL HashSet&lt;String&gt; (3 items) BU ALL EMP HashSet&lt;String&gt; (3 items) BU ALL SS HashSet&lt;String&gt; (2 items) BU EMP HashSet&lt;String&gt; (3 items) BU EMP SS HashSet&lt;String&gt; (3 items) BU CONF ALL HashSet&lt;String&gt; (3 items) BU CONF EMP HashSet&lt;String&gt; (3 items) BU CONF SS HashSet&lt;String&gt; (3 items) BU CON1 ALL HashSet&lt;String&gt; (3 items) BU CON1 EMP HashSet&lt;String&gt; (3 items) BU CON1 SS </code></pre> <p><strong>Update:</strong> Here is the same algorithm in VB.NET (it looks very much the same):</p> <pre><code>Dim Empty As IEnumerable(Of IEnumerable(Of String)) = Enumerable.Repeat(Enumerable.Empty(Of String)(), 1) Data.Aggregate(Empty, _ Function(accumulator, kvp) _ From a in accumulator _ From i in kvp.Value _ Select a.Concat(Enumerable.Repeat(i, 1))) _ .Select(Function([set]) New HashSet(Of String)([set])) _ .Distinct(HashSet(Of String).CreateSetComparer()) </code></pre>
    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