title: Getting the average of observable collection element data
body: <p>I have an observablecollection containing 60 elements, each containing data of numbers(double). I would like to get the average of the 60 elements( (total sum of 60 elements)/60). Any idea how I can go about it?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class MainWindow : Window
  {            
      DispatcherTimer timer = new DispatcherTimer();
      double i = 0;
      ObservableCollection&lt;KeyValuePair&lt;double, double&gt;&gt; Power = new ObservableCollection&lt;KeyValuePair&lt;double, double&gt;&gt;();
  
      public MainWindow()
      {
          InitializeComponent();
  
          timer.Interval = new TimeSpan(0, 0, 1);  // per 5 seconds, you could change it
          timer.Tick += new EventHandler(timer_Tick);
          timer.IsEnabled = true;
      }
  
   Random random = new Random(DateTime.Now.Millisecond);
  
      void timer_Tick(object sender, EventArgs e)
      {
  
          Power.Add(new KeyValuePair&lt;double, double&gt;(i, random.NextDouble() ));
          i += 5;
  
      }
  }
  </code></pre>