title: How to get a list of the grouped values in linq groupby?
body: <p>Linq newbie here, struggling with my first group by query.</p>
  
  <p>I have a list of objects of type KeywordInstance which represent a keyword, and the ID of the database record to which the keyword was applied. </p>
  
  <pre><code>Keyword      RecordID
  macrophages  1
  macrophages  2
  cell cycle   3 
  map kinase   2
  cell cycle   1
  </code></pre>
  
  <p>What I want to have is a collection of all keywords, with a list of the RecordIDs to which each keyword was applied </p>
  
  <pre><code>Keyword     RecordIDs 
  macrophages 1, 2
  cell cycle  1, 3
  map kinase  2
  </code></pre>
  
  <p>I tried using Linq to get it into a new object. I only managed to get the distinct keywords. </p>
  
  <p>var keywords = allWords
          .GroupBy(w => w.keyword)
          .Select(g => new {keyword = g.Key});</p>
  
  <p>The problem is that I can't seem to get the values of g in any way. g is of the type IGrouping and by documentation, it only has the property Key, but not even the property Value. All the examples I have seen on the Internet for groupby just tell me to select g itself, but the result of </p>
  
  <pre><code>var keywords = allWords
      .GroupBy(w =&gt; w.keyword)
      .Select(g =&gt; new {keyword = g.Key, RecordIDs = g});
  </code></pre>
  
  <p>is not what I want. </p>
  
  <p><img src="https://i.stack.imgur.com/3rCNb.png" alt="screenshot of result"></p>
  
  <p>Any try to get something out of g fails with the error message <code>System.Linq.IGropuing&lt;string, UserQuery.KeywordInstance&gt; does not have a definition for [whatever I tried]</code>. </p>
  
  <p>What am I doing wrong here? </p>