Click here to Skip to main content
15,888,301 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've got problems implementing System.Collections.Generic.IEnumerator<T>. I have to implement both IEnumerator<T>.Current and IEnumerator.Current. This leads to a conflict of 2 properties with the same name.

The funniest thing about it - I cannot compile an msdn example.
It gives:
error CS0305: Using the generic type 'System.Collections.Generic.IEnumerator<t>' requires '1' type arguments
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll: (Related file)
error CS0738: 'Network.Node<t>.BoxEnumerator' does not implement interface member 'System.Collections.IEnumerator.Current'. 'Network.Node<t>.BoxEnumerator.Current' cannot implement 'System.Collections.IEnumerator.Current' because it does not have the matching return type of 'object'.
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll: (Related file)</t></t></t>


Can anyone help me with this? C# is very new to me. Thanks in advance
Posted
Comments
voloda2 3-Nov-10 16:04pm    
Did you tried explicit implementation of interfaces?

Implement IEnumerator<T> normally, and IEnumerator explicitly. Then have the IEnumerator version return the IEnumerator<T>.Current.

[Edit]
--------

Btw to get the MSDN code to compile, add dummy classes for Box and BoxCollection:

C#
class Box { }

class BoxCollection : Collection<Box> { }
 
Share this answer
 
v2
Comments
japcrword 3-Nov-10 16:45pm    
Thank you very much.
Nish Nishant 3-Nov-10 16:46pm    
You are most welcome :-)
 
Share this answer
 
v2
Comments
Nish Nishant 3-Nov-10 16:30pm    
See how I've derived BoxCollection from Collection<Box>.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900