I have encountered a pair of related compiler errors. I am unable to decipher the compiler's error messages. The solution SHOULD BE brain-dead simple.
Could you please reply with the worked out solution? It should be a single line of code.
Here's my code, as stripped-down as possible while still exhibiting the error:
using System;
using System.Collections.Generic;
public class Bar { }
//---- Foo
public class Foo : IEnumerator<Bar>
{
Bar[] bars;
private int curIndex;
private Bar curBar;
public Foo(Bar[] collection) { }
public bool MoveNext() { return true; }
public void Reset() { }
void IDisposable.Dispose() { }
public Bar Current { get { return curBar; } }
object IEnumerator<Bar>.Current { get { return Current; } }
} // class Foo
When I attempt to compile that code, I get two compiler errors, as follows:
- CS0539: 'Foo.Current' in explicit interface declaration is not found among members of the interface that can be implemented.
- CS0738 'Foo' does not implement interface member 'IEnumerator.Current'. 'Foo.Current' cannot implement 'IEnumerator.Current' because it does not have the matching return type of 'object'.
Regarding CS0539, my understanding of the phrase "explicit interface declaration" suggests that the code below is the "explicit interface declaration" that the compiler is insisting does not exist:
public Bar Current { get { return curBar; } }
Regarding CS0738, when I try to add an interface member IEnumerator.Current that returns an object, the compiler barfs two different error messages:
- CS0305 Using the generic type 'IEnumerator' requires 1 type arguments.
- CS0538 'IEnumerator' in explicit interface declaration is not an interface.
Therefore, I am trapped in a in a maze of twisty little passages, all alike, offering no escape. I have no idea how to resolve this problem. Hours of Googling have been unproductive.
P.S.: Why am I implementing an enumerator rather than [whatever]? Because my use-case requires an enumeration of one cycle around a circular collection of values. I had expected to steal... I mean, borrow... I mean, "reuse" an existing CircularEnumerator class, but I could not find one -- or, at least, not one that my tiny little brain could understand. Thanks! :-)