title: How do I implement IEnumerable in my Dictionary wrapper class that implements IEnumerable<Foo>?
body: <p>I'm trying to create a wrapper for a <code>Dictionary&lt;String,Foo&gt;</code>.</p>
  
  <p><code>Dictionary&lt;String,Foo&gt;</code> implements <code>IEnumerable&lt;KeyValuePair&lt;String,Foo&gt;&gt;</code>, but I want my wrapper class to implement <code>IEnumerable&lt;Foo&gt;</code>.  So I tried this:</p>
  
  <pre><code>public class FooCollection : IEnumerable&lt;Foo&gt;
  {
      private Dictionary&lt;string, Foo&gt; fooDictionary = new Dictionary&lt;string, Foo&gt;();
  
      public IEnumerator&lt;Foo&gt; GetEnumerator()
      {
          return fooDictionary.Values.GetEnumerator();
      }
  
      // Other wrapper methods omitted
  
  }
  </code></pre>
  
  <p>However I get this error:</p>
  
  <blockquote>'FooCollection' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'.  'FooCollection.GetEnumerator()' cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because it does not have the matching return type of 'System.Collections.IEnumerator'.</blockquote>
  
  <p>However I don't understand this error, because <code>FooCollection.GetEnumerator()</code> returns an <code>IEnumerator&lt;Foo&gt;</code>, and <code>IEnumerator&lt;Foo&gt;</code> is an <code>IEnumerator</code>.</p>
  
  <p>EDIT:</p>
  
  <p>The solution of explicitly implementing <code>IEnumerator.GetEnumerator()</code> works.  However I'm now wondering why when I "Go to definition" on a <code>List&lt;T&gt;</code> I see only one definition of GetEnumerator:
  <code>public List&lt;T&gt;.Enumerator GetEnumerator();</code></p>
  
  <p>Apparently <code>List&lt;T&gt;</code> can have a single <code>GetEnumerator</code> method that returns something that implements both <code>IEnumerator&lt;T&gt;</code> and <code>IEnumerator</code>, but I have to have one method for each?</p>
  
  <p>EDIT:</p>
  
  <p>As answered by LukeH below, <code>List&lt;T&gt;</code> <em>does</em> include the explicit interface implementations.  Apparently Visual Studio just doesn't list those when generating method stubs from the metadata. (See this previous question: <a href="https://stackoverflow.com/questions/7268632/why-does-the-vs-metadata-view-does-not-display-explicit-interface-implemented-mem">Why does the VS Metadata view does not display explicit interface implemented members</a> )</p>
  
  <p>Before posting this question I had tried checking <code>List&lt;T&gt;</code> (via "Go to Definition" in Visual Studio) to see if I needed to implement multiple versions of GetEnumerator. I guess this wasn't the most reliable way to check.</p>
  
  <p>Anyway, I'm marking this as answered. Thanks for your help.</p>