title: Time-stamped, thread-safe data structure for time-based lookup?
body: <p>I want to implement a list type data structure that can be appended to, with an associated time-stamp. The point of this is that I can then get all the data that is newer than a certain time-stamp.</p>
  
  <p>I have tried doing this with a ConcurrantDicitionary but I'm not confident this is the best way to do it. I would much prefer to have a List&lt; decimal[2] >  for applications which I won't go into here. The first value of the array can have the timestamp and the second will be the value. Alternatively, could use List&lt; TimeStampedObject >. However, <a href="https://stackoverflow.com/questions/6601611/no-concurrentlistt-in-net-4-0">apparently</a> there is no such thing as a concurrent list in C#.</p>
  
  <p>For the record, my data is ordered with regards to timestamp.</p>
  
  <p>I want to be able to do things like:</p>
  
  <pre><code>public static Dictionary&lt;DateTime, decimal&gt; GetLatest(DateTime since, Dictionary&lt;DateTime, decimal&gt; requestedDict)
  {
      Dictionary&lt;DateTime, decimal&gt; returnList = new Dictionary&lt;DateTime, decimal&gt;();
      returnList = requestedDict.Where(x =&gt; x.Key &gt; since).ToDictionary(x =&gt; x.Key, x =&gt; x.Value);
      return returnList;
  }
  </code></pre>
  
  <ul>
  <li><strong>UPDATE:</strong></li>
  </ul>
  
  <p>Here is the List item I have come up with; please let me know if this has any potential downfalls:</p>
  
  <pre><code>public class ConcurrentList: List&lt;StampedValue&gt;
      {
  
          ReaderWriterLockSlim _samplesLock = new ReaderWriterLockSlim();
  
          public ConcurrentList() : base()
          {
          }
  
          public void AddThreadSafe(StampedValue item){
  
              this._samplesLock.EnterWriteLock();
              try
              {
                  this.Add(item);
  
              }
              finally
              {
                  this._samplesLock.ExitWriteLock();
              }
  
          }
  
          public List&lt;StampedValue&gt; GetLatest(long since){
              return this.Where( s =&gt; s.Timestamp &gt; since ).ToList();
          }
  
          public List&lt;StampedValue&gt; GetLatest(DateTime since){
              throw new NotImplementedException();
          }
      }
  
  
      public class StampedValue
      {
          public long Timestamp { get; set; }
          public decimal Value { get; set; }
  
          public StampedValue(long t, decimal v){
              this.Timestamp = t;
              this.Value = v;
          }
  
      }
  </code></pre>