IEnumerator<T>.Current

The following code was compiling fine under Beta 1 but now generates the following error:
'Enumerator<T>' does not implement interface member 'System.Collections.IEnumerator.Current'.
'Enumerator<T>.Current' is either static, not public, or has the wrong return type.

class Enumerator<T> : System.Collections.Generic.IEnumerator<T>
{
   private T m_current;
   public T Current
   {
      get
      {
         return m_current;
      }
   }

   // ...
}

I can't figure out what the return type should be if not 'T'.

Chris.



Answer this question

IEnumerator<T>.Current

  • Kapitein Stijn

    In order to implement IEnumerable properly, you must also write Current returning Object. In other words, in addition to the "public T Current" you must implement "public Object Current".

    Thanks,

    --
    Boris Jabes, Visual C++
    This post is provided "AS IS" with no warranties and provides no rights

  • IGlez

    How do you do that

    When I try I get a different error:

    "already contains definition for 'Current'"


  • Inbar Gazit - MSFT

    Chris,
    I am having same issue with Beta 2. Did you resolve this
    Thanks,
    Rick

  • marcel123

    How do you do this in c#
  • joe2000

    property Object^ IEnumerator_Current
    {
    virtual Object^ get()=System::Collections::IEnumerator::Current::get { return Current; }
    }

  • Flemming Wagner

    object System.Collections.IEnumerator.Current
    {
    get { return this.Current; }
    }


  • IEnumerator<T>.Current