title: .NET queue ElementAt performance
body: <p>I'm having a hard time with parts of my code:</p>
  
  <pre><code>    private void UpdateOutputBuffer()
      {
          T[] OutputField = new T[DisplayedLength];
  
          int temp = 0;
          int Count = HistoryQueue.Count;
          int Sample = 0;
  
          //Then fill the useful part with samples from the queue
          for (temp = DisplayStart; temp != DisplayStart + DisplayedLength &amp;&amp; temp &lt; Count; temp++)
          {
              OutputField[Sample++] = HistoryQueue.ElementAt(Count - temp - 1);
          }
  
          DisplayedHistory = OutputField;
      }
  </code></pre>
  
  <p>It takes most of the time in the program. The number of elements in HistoryQueue is 200k+. <strong>Could this be because the queue in .NET is implemented internally as a linked list?</strong> </p>
  
  <p><strong>What would be a better way of going about this?</strong> Basically, the class should act like a FIFO that starts dropping elements at ~500k samples and I could pick DisplayedLength elements and put them into OutputField. I was thinking of writing my own Queue that would use a circular buffer.</p>
  
  <p>The code worked fine for count lower values. DisplayedLength is 500.</p>
  
  <p>Thank you, </p>
  
  <p>David</p>