title: Calculate difference from previous item with LINQ
body: <p>I'm trying to prepare data for a graph using LINQ.</p>
  
  <p>The problem that i cant solve is how to calculate the "difference to previous. </p>
  
  <p>the result I expect is </p>
  
  <p>ID= 1,  Date= Now, DiffToPrev= 0;</p>
  
  <p>ID= 1,  Date= Now+1, DiffToPrev= 3;</p>
  
  <p>ID= 1,  Date= Now+2, DiffToPrev= 7;</p>
  
  <p>ID= 1,  Date= Now+3, DiffToPrev= -6;</p>
  
  <p>etc...</p>
  
  <p>Can You help me create such a query ? </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace ConsoleApplication1
  {
      public class MyObject
      {
          public int ID { get; set; }
          public DateTime Date { get; set; }
          public int Value { get; set; }
      }
  
      class Program
      {
          static void Main()
          {
                 var list = new List&lt;MyObject&gt;
            {
              new MyObject {ID= 1,Date = DateTime.Now,Value = 5},
              new MyObject {ID= 1,Date = DateTime.Now.AddDays(1),Value = 8},
              new MyObject {ID= 1,Date = DateTime.Now.AddDays(2),Value = 15},
              new MyObject {ID= 1,Date = DateTime.Now.AddDays(3),Value = 9},
              new MyObject {ID= 1,Date = DateTime.Now.AddDays(4),Value = 12},
              new MyObject {ID= 1,Date = DateTime.Now.AddDays(5),Value = 25},
              new MyObject {ID= 2,Date = DateTime.Now,Value = 10},
              new MyObject {ID= 2,Date = DateTime.Now.AddDays(1),Value = 7},
              new MyObject {ID= 2,Date = DateTime.Now.AddDays(2),Value = 19},
              new MyObject {ID= 2,Date = DateTime.Now.AddDays(3),Value = 12},
              new MyObject {ID= 2,Date = DateTime.Now.AddDays(4),Value = 15},
              new MyObject {ID= 2,Date = DateTime.Now.AddDays(5),Value = 18}
  
          };
  
              Console.WriteLine(list);   
  
              Console.ReadLine();
          }
      }
  }
  </code></pre>