Note that there are some explanatory texts on larger screens.

plurals
  1. POILookup<TKey, TVal> vs. IGrouping<TKey, TVal>
    text
    copied!<p>I've been having trouble articulating the differences between <a href="http://msdn.microsoft.com/en-us/library/bb534291.aspx"><code>ILookup&lt;TKey, TVal&gt;</code></a> and <a href="http://msdn.microsoft.com/en-us/library/bb344977.aspx"><code>IGrouping&lt;TKey, TVal&gt;</code></a>, and am curious if I understand it correctly now. LINQ compounded the issue by producing sequences of <code>IGrouping</code> items while also giving me a <code>ToLookup</code> extension method. So it felt like they were the same until I looked more closely.</p> <pre><code>var q1 = from n in N group n by n.MyKey into g select g; // q1 is IEnumerable&lt;IGrouping&lt;TKey, TVal&gt;&gt; </code></pre> <p>Which is equivalent to:</p> <pre><code>var q2 = N.GroupBy(n =&gt; n.MyKey, n =&gt; n); // q2 is IEnumerable&lt;IGrouping&lt;TKey, TVal&gt;&gt; </code></pre> <p>Which looks a lot like:</p> <pre><code>var q3 = N.ToLookup(n =&gt; n.MyKey, n =&gt; n); // q3 is ILookup&lt;TKey, TVal&gt; </code></pre> <p>Am I correct in the following analogies?</p> <ol> <li>An <code>IGrouping&lt;TKey, TVal&gt;</code> is a single group (i.e. a keyed sequence), analogous to <code>KeyValuePair&lt;TKey, TVal&gt;</code> where the value is actually a sequence of elements (rather than a single element)</li> <li>An <code>IEnumerable&lt;IGrouping&lt;TKey, TVal&gt;&gt;</code> is a sequence of those (similar to what you get when iterating over an <code>IDictionary&lt;TKey, TVal&gt;</code></li> <li>An <code>ILookup&lt;TKey, TVal&gt;</code> is more like a <code>IDictionary&lt;TKey, TVal&gt;</code> where the value is actually a sequence of elements</li> </ol>
 

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