Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Dear All,

 

 

I'm trying to implement the ICollection(Of T) interface. This would be fairly straight forward, but for some reason there are two implementations of the GetEnumerator function:

'Returns an enumerator to the address...
Public Function GetEnumerator() _
 As System.Collections.Generic.IEnumerator(Of IAddress) _
 Implements System.Collections.Generic.IEnumerable(Of IAddress).GetEnumerator
   ....
End Function

'Returns an enumerator to the IEnumerable interface...
Public Function GetEnumerator1() _
 As System.Collections.IEnumerator _
 Implements System.Collections.IEnumerable.GetEnumerator
   ....
End Function

I can understand that the second enumerator function is there due to the implementation of the IEnumerator in the ICollection interface, but what implications does it have on the operation of the class, and should I code it up independantly with an equivalent enumeration class?

 

 

Kind regards

Paul Weston

  • Administrators
Posted

You could probably just do something like

Public Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
       Return GetEnumerator()
End Function

unless you really did require special handling of the non-generic version.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

It's quite surprising that it's included, really, especially as I would have thoguht the 'Of T' should limit the class to a specific type...

 

Thanks for your help PD. ;)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...