From: Peter Duniho on
Rich P wrote:
> [...]
> I added a private class for iterating, and that caused 2 errors to pop up.
> If I remove the private class - the errors go away. Currently, I don't
> have enough background with Interfaces and am having diffuculty
> proceeding. Here are the 2 error messages I am getting with what I have
> so far, and below that is the code:
>
> Error 1
> 'InterfaceDictionary.MyClassCollection.MyClassCollectionEnumerator' does
> not implement interface member
> 'System.Collections.IEnumerable.GetEnumerator()'
>
> Error 2
> 'InterfaceDictionary.MyClassCollection.MyClassCollectionEnumerator' does
> not implement interface member
> 'System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyVa
> luePair<int,InterfaceDictionary.MyClass>>.GetEnumerator()'
>
> here is my code -- how can I make this work?

I'm not sure what seems so confusing about the error messages, but they
are telling you exactly what you need to know. Your type does not
implement the interface members described in the error messages and to
make the errors go away you have to implement those members.

Why you're implementing a whole enumerator class at all, I don't really
know. There's no need to, as I pointed out in your previous thread
about this question. But if you're going to do so, you have to
implement the methods you promised to implement in your class declaration.

Note also that you've declared the class as implementing
IEnumerable<KeyValuePair<int, MyClass>>, when in fact it should be
implementing IEnumerator<KeyValuePair<int, MyClass>>. That's the
interface type your GetEnumerator() methods in the outer class are
required to return, and that's the interface you have to implement.

As far as what to implement, frankly the interface declaration ought to
be enough (along with the error messages that tell you what you haven't
implemented). But if you're ever at a loss, you can just right-click on
the interface name in the class declaration and choose the
"Implement�interface" command (or just put the text cursor there and
press Ctrl-.). The IDE will then insert the appropriate member stubs
for the interface, which you can then just fill out with actual
implementation.

Pete