Results 1 to 6 of 6

Thread: Problem implementing the IDictionary Interface

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Location
    Nottingham
    Posts
    14

    Problem implementing the IDictionary Interface

    I am trying to implement the IDictionary interface in a class and the framework is telling me to implement the Overridable Overloads Function GetEnumerator() as IDictionaryEnumerator method. If I add it using the drop down combo at the top of the editor it inserts the method for me.

    However the class still has an error because it also wants me to implement Overridable Overloads Function GetEnumerator() as IEnumerator. Obviously I can't do this because the methods only differ by return type!! Has anyone else encountered this problem or does someone know of a solution ?

    Thanks in advance

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Obviously I can't do this because the methods only differ by return type!!
    Umm yes you can. Do exactly what it tells you to do.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Location
    Nottingham
    Posts
    14
    I have done what it tells me to do and that's what is causing the error !

    This is the code I've added to my class.
    Code:
     
    <Serializable()> Public Class ReportOutputModelList : Implements IDictionary
    
           Public Overridable Overloads Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
               
            End Function
    
            Public Overridable Overloads Function GetEnumerator() As IDictionaryEnumerator Implements IDictionary.GetEnumerator
                
            End Function
    
    etc...
    
    End Class
    It is saying it needs both these methods but having added them I then get the 'cannot overload each other because they differ only by return types.'

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Just rename 1 of them. As long as they Implement the correct method, name doesnt matter
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Location
    Nottingham
    Posts
    14
    Thanks Cander.

    That wasn't immediately obvious. It must just look for a match on the Implements statement on the method declaration to complete the implementation, I guess !

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    I could be worng, but they seems to be the case.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width