title: Implementing IEnumerable with an Array
body: <p>This is likely a simple syntax question, but I can't figure it out.</p>
  
  <p>Normally, I would do this:</p>
  
  <pre><code>public class OrderBook : IEnumerable&lt;PriceLevel&gt;
  {
      private readonly List&lt;PriceLevel&gt; PriceLevels = new List&lt;PriceLevel&gt;();
  
      public IEnumerator&lt;PriceLevel&gt; GetEnumerator()
      {
          return PriceLevels.GetEnumerator();
      }
  
      IEnumerator IEnumerable.GetEnumerator()
      {
          return PriceLevels.GetEnumerator();
      }
  }
  </code></pre>
  
  <p>But instead of a list, I want to use an array - like this:</p>
  
  <pre><code>public class ArrayOrderBook : IEnumerable&lt;PriceLevel&gt;
  {
      private PriceLevel[] PriceLevels = new PriceLevel[500];
  
      public IEnumerator&lt;PriceLevel&gt; GetEnumerator()
      {
          return PriceLevels.GetEnumerator();
      }
  
      IEnumerator IEnumerable.GetEnumerator()
      {
          return PriceLevels.GetEnumerator();
      }
  }
  </code></pre>
  
  <p>The <code>IEnumerator IEnumerable.GetEnumerator()</code> seems to compile fine - but the public <code>IEnumerator&lt;PriceLevel&gt;</code> says that I need some kind of cast - what is the best way of doing this?</p>
  
  <p>William</p>