title: How to return different sets of duplicates from a list
body: <p>I have the following list of objects:</p>
  <pre><code>ConnectionType = ConnectionType.COM
  ComPort = &quot;com1&quot;
  TcpPort = null
  ConnectionName = &quot;CONN0&quot;
  
  ConnectionType = ConnectionType.COM
  ComPort = &quot;COM1&quot;
  TcpPort = null
  ConnectionName = &quot;CONN1&quot;
  
  ConnectionType = ConnectionType.COM
  ComPort = &quot;COM1&quot;
  TcpPort = null
  ConnectionName = &quot;CONN2&quot;
  
  ConnectionType = ConnectionType.COM
  ComPort = &quot;COM2&quot;
  TcpPort = null
  ConnectionName = &quot;CONN3&quot;
  
  ConnectionType = ConnectionType.IP
  ComPort = null
  TcpPort = 1234
  ConnectionName = &quot;CONN4&quot;
  
  ConnectionType = ConnectionType.IP
  ComPort = null
  TcpPort = 1234
  ConnectionName = &quot;CONN5&quot;
  
  ConnectionType = ConnectionType.IP
  ComPort = null
  TcpPort = 4321
  ConnectionName = &quot;CONN6&quot;
  </code></pre>
  <p>Types used in each object:</p>
  <pre><code>private int? tcpPort;
  private string comPort;
  private string connectionName;
  private ConnectionType connectionType;
  </code></pre>
  <p>What LINQ query would return a lookup/dictionary of duplicates for each ConnectionType? Results should include a ComPort/TcpPort and ConnectionName for each duplicate. As for ComPort, the query should match strings ignoring the case too.</p>
  <p>So far I have been able to retrieve somewhat the desirable outcome with the following query:</p>
  <pre><code>var duplicates = myList
              .GroupBy(x =&gt; new { x.ComPort, x.TcpPort }).
              .Where(m =&gt; m.Key != null &amp;&amp; m.Skip(1).Any());
  </code></pre>
  <p>Which returns the following:</p>
  <pre><code>{ ComPort = COM1, TcpPort =  }
       CONN1
       CONN2
  { ComPort = , TcpPort = 1234 }
       CONN4
       CONN5
  </code></pre>
  <p>However the result output should look like the following:</p>
  <pre><code>COM1
      CONN0
      CONN1
      CONN2
  
  1234
      CONN4
      CONN5
  </code></pre>