title: Multiple columns in Linq
body: <p>Problem:  how to simplify the code below, as I'm aiming towards 30 different properties in the thing class.</p>
  
  <p>The code looks for uniqueness in a 'thing' property.</p>
  
  <pre><code>public class thing
  {
      public string Name { get; set; }
      public string Colour { get; set; }
      public string Position { get; set; }
      public string Height { get; set; }
  }
  
  public List&lt;thing&gt; SeeIfAnyInListHaveAUniqueSingleColumn(List&lt;thing&gt; listOfThings)
      {
          // try colour
          IEnumerable&lt;IGrouping&lt;string, thing&gt;&gt; thingQuery2 = from t in listOfThings
                                                              group t by t.Colour;
          List&lt;thing&gt; listOfThingsFound = new List&lt;thing&gt;();
          foreach (var thingGroup in thingQuery2)
          {
              if (thingGroup.Count() == 1)
              {
                  foreach (thing thing in thingGroup) // there is only going to be 1
                      listOfThingsFound.Add(thing);
              }
          }
  
          // try position
          IEnumerable&lt;IGrouping&lt;string, thing&gt;&gt; thingQuery3 = from t in listOfThings
                                                              group t by t.Position;
  
          foreach (var thingGroup in thingQuery3)
          {
              if (thingGroup.Count() == 1)
              {
                  foreach (thing thing in thingGroup) // there is only going to be 1
                      listOfThingsFound.Add(thing);
              }
          }
          return listOfThingsFound;
      }
  </code></pre>
  
  <p>Downloadable code on <a href="http://www.programgood.net/2010/11/06/FindingUniquenessInData.aspx" rel="nofollow">http://www.programgood.net/2010/11/06/FindingUniquenessInData.aspx</a></p>