<p>Another easy one hopefully.</p>

<p>Let's say I have a collection like this:</p>

<pre><code>List&lt;DateTime&gt; allDates;
</code></pre>

<p>I want to turn that into </p>

<pre><code>List&lt;List&lt;DateTime&gt;&gt; dividedDates;
</code></pre>

<p>where each List in 'dividedDates' contains all of the dates in 'allDates' that belong to a distinct year.</p>

<p>Is there a bit of LINQ trickery that my tired mind can't pick out right now?</p>

<p><strong>Solution</strong></p>

<p>The Accepted Answer is correct.</p>

<p>Thanks, I don't think I was aware of the 'into' bit of GroupBy and I was trying to use the .GroupBy() sort of methods rather than the SQL like syntax.  And thanks for confirming the ToList() amendment and including it in the Accepted Answer :-)</p>

[{'answer_id': 69769, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 4, 'selected': True, 'text': '<pre><code>var q  = from date in allDates \n         group date by date.Year into datesByYear\n         select datesByYear.ToList();\nq.ToList(); //returns List&lt;List&lt;DateTime&gt;&gt;\n</code></pre>\n'}, {'answer_id': 72171, 'author': 'Amy B', 'author_id': 8155, 'author_profile': 'https://Stackoverflow.com/users/8155', 'pm_score': 3, 'selected': False, 'text': "<p>Here's the methods form.</p>\n\n<pre>\nallDates\n  .GroupBy(d => d.Year)\n  .Select(g => g.ToList())\n  .ToList();\n</pre>\n"}]
['https://Stackoverflow.com/questions/69748', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/364/']