title: C# Linq statements or a foreach() for totalling subsets?
body: <p>Which of these solutions is preferred?  </p>
  
  <p>For a List:</p>
  
  <pre><code>List&lt;ExampleInfo&gt; exampleList = new List&lt;ExampleInfo&gt;();
  
  public class ExampleInfo
  {
      internal ExampleInfo()
      { }
      /* Business Properties */
      public int Id { get; set; }
      public string Type { get; set; }
      public decimal Total { get; set; }
  }
  </code></pre>
  
  <p>I wish to get subtotals based off the 'Total' value.  </p>
  
  <p>Option 1:    </p>
  
  <pre><code>var subtotal1 = exampleList.Where(x =&gt; x.Type == "Subtype1").Sum(x =&gt; x.Total);
  var subtotal2 = exampleList.Where(x =&gt; x.Type == "Subtype2").Sum(x =&gt; x.Total);
  </code></pre>
  
  <p>Option 2:  </p>
  
  <pre><code>decimal subtotal1 = 0m;
  decimal subtotal2 = 0m;
  foreach (ExampleInfo example in exampleList)
  {
      switch (example.Type)
      {
          case "Subtype1":
              subtotal1 += example.Total;
               break;
          case "Subtype2":
               subtotal2 += example.Total;
               break;
          default:
               break;
  
      }
  }
  </code></pre>
  
  <p>The list will be &lt;10 items in most cases.  </p>
  
  <p><b>Edit:</b> Chris raised a very good point I did not mention. The program is already using .NET Framework 3.5 SP1 so compatibility isn't an important consideration here.</p>