Women in Technology

Hear us Roar



Article:
  C# Generics: Collection Interfaces
Subject:   VB
Date:   2006-03-22 17:13:53
From:   woaksie
I am trying to use IEnumerator<T> in VB 2005. My class implements the IEnumerable<T> interface and I define a method GetEnumerator that returns a IEnumerator<T>.


The compiler is asking me to define a GetEnumerator method (the non generic version). But you cannot have two methods that that only differ by return type.


I think this is because the IEnumerable<T> interface implements the IEnumerable interface.


Also my GetEnumerator<T> method does a return mList.GetEnumerator() where mList is of type List<T>. Is there a yield command in VB 2005?


Thanks.

Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • VB
    2008-01-18 06:06:22  integragreg [View]

    >>But you cannot have two methods that that only differ by return type.>>

    Actually, you can. Check out explicit interface implementation...
  • VB
    2006-03-23 04:24:31  JesseLiberty [View]

    Yes, the interface was changed with the final release. The net effect is that the code fails with an error that you have not implemented the GetEnumerator() method. To work around this, you must implement a non-generic GetEnumerator to your class.

    Since the signature is identical, you must implement it explicitly. Here is work around code:

    IEnumerator IEnumerable.GetEnumerator()
    {
    throw new NotImplementedException();
    }

    Be sure to add using System.Collections;