title: How to check for duplicate property values given a list of objects and return the objects?
body: <p>Referring to <a href="https://stackoverflow.com/questions/312024/linqy-way-to-check-if-any-objects-in-a-collection-have-the-same-property-value">this post</a>, the original poster needed to find all <code>agent</code> objects in a list that had the same <code>ID</code> property value.</p>
  
  <pre><code> var duplicates = agents.GroupBy(a =&gt; a.ID).Where(a=&gt;a.Count() &gt; 1);
  
   foreach (var agent in duplicates)
   {
           Console.WriteLine(agent.Key.ToString());
   }
  </code></pre>
  
  <p>The above was the given solution, but I can't figure out how to access the objects in "duplicates". If I do the following:</p>
  
  <pre><code> var duplicates = agents.GroupBy(a =&gt; a.ID).Where(a=&gt;a.Count() &gt; 1);
  
   foreach (var agent in duplicates)
   {
           Console.WriteLine(agent.ID);
           agent.duplicate = true;
  
   }
  </code></pre>
  
  <p>I get </p>
  
  <blockquote>
    <p>'IGrouping' does not contain a definition for 'ID' and no extension method 'ID' accepting a first argument of type 'IGrouping' could be found (are you missing a using directive or an assembly reference?)</p>
  </blockquote>