title: Using LINQ to Get Sum/ Average of a List with custom objects
body: <p>I have a class:</p>
  
  <pre><code>public class PointD
  {
      public double X
      { get; set; }
      public double Y
      { get; set; }
  
      public PointD(double x, double y)
      {
          X = x;
          Y=y;
      }
     //operator for +,-, * and / are overridden
   }
  </code></pre>
  
  <p>Given a <code>list&lt;PointD&gt;</code>, how to get the average of it using LINQ? A <code>for</code> loop equivalent will be something like this:</p>
  
  <pre><code>  double xx, yy;
    for ( int i=0; i&lt; ptlist.Count; i++)
       {
           xx+=ptlist[i].X;
           yy+=ptlist[i].Y; 
       }
    return new PointD(){X=xx, Y=yy};
  </code></pre>
  
  <p>You can use any <strong>built-in</strong> LINQ function only. You can't define an extension that takes care of this function.</p>
  
  <p>Any idea?</p>
  
  <p><strong>Edit: Of course, you can use two separate <code>Sum</code> extension method to Sum for X and Y component before merging them. But this is not what I want. What I want is a single query/ method that does the job</strong> </p>