IEnumerable<T> compile error

Hi All,

I have a class that implements IEnumerable<T>.

public class ShiftBuffer<T> : IEnumerable<T>

I am wrapping a Queue<T>. I have implemented the method:

public IEnumerator<T> GetEnumerator() {

return null;// queue.GetEnumerator();

}

However I get a compile error saying that I have not implemented IEnumerable.GetEnumerator()

Error 1 'CSharpUtilities.Collections.ShiftBuffer<T>' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'CSharpUtilities.Collections.ShiftBuffer<T>.GetEnumerator()' is either static, not public, or has the wrong return type. E:\My Documents\Work\Generic Projects\CSharp\CSharpUtilities\Collections\ShiftBuffer.cs 64 15 CSharpUtilities

However, if I implement both:

public IEnumerator<T> GetEnumerator() {

return null;// queue.GetEnumerator();

}

public IEnumerator GetEnumerator() {

return null;// queue.GetEnumerator();

}

I of course get the method already defined error.

If I only define

public IEnumerator GetEnumerator() {

return null;// queue.GetEnumerator();

}

I get the error that I have not defined IEnumerable<T>.GetEnumerator.

What is going on



Answer this question

IEnumerable<T> compile error

  • yjoe3

    try:prefixing the latter with the non generic interface name. . .

    public IEnumerator<T> GetEnumerator() {

    return null;// queue.GetEnumerator();

    }

    public IEnumerator IEnumerable.GetEnumerator() {

    return null;// queue.GetEnumerator();

    }

    that should work.

    Code generation should generated it for ou too.



  • Howard555

    Coolo! I didn't know about the code generation. It did the trick. Thanks.
  • IEnumerable<T> compile error