title: Calculate sum using LINQ
body: <pre><code>foreach (Item item in Items)
                          {
                              Cost = Cost +
                                      item.Costs.OrderByDescending(x =&gt; x.ID)
                                                .FirstOrDefault()
                                                .Cost;
  
                          }
  </code></pre>
  
  <p>The above LINQ returns 150.</p>
  
  <p>I have 4 items(1,2,3,4) with the respective Cost. I need to rewrite the above LINQ to get the correct total cost of 210.</p>
  
  <p>ID--ItemID--   Cost</p>
  
  <p>11 --       1   --    10</p>
  
  <p>21  --    2   --  20</p>
  
  <p>31   --   2   --  30</p>
  
  <p>41  --    3  --   40</p>
  
  <p>51  --    3  --   50</p>
  
  <p>61  --   4   --  60</p>
  
  <p>Can anyone please provide the modified LINQ to do so?</p>
  
  <p>Modifying the LINQ as below doesnt give me the expected result --</p>
  
  <pre><code>foreach (Item item in Items)
                      {
                          Cost = Cost +
                                  item.Costs.Sum(r =&gt; r.Cost);
                      }
  </code></pre>