Override become Overload? 
Author Message
 Override become Overload?

I have a dictionary class named TestDictionary that is
derived from StringDictionary. Within TestDictionary, I
override the Add(string key, string value) method. The
class compiles fine and works fine. But one thing bothers
me: When I use the Add() method of TestDictionary class in
Visual Studio, Intelisense would show that there are two
overloaded Add() methods available:

   void TestDictionary.Add(string key, string value)
   void StringDictionary.Add(string key, string value)

Why is this the case? Since the TestDictionary.Add()
overrides the StringDictionary.Add(), shouldn't it be that
only TestDictionary.Add() be available?

Since both two methods has the same signature, if both are
available, how could CLR know which one I intend to use?

Following is the code. Any insight are appreciated.

using System;
using System.Collections.Specialized;
public class TestDictionary:StringDictionary {
   public TestDictionary(){}
   public override void Add(string key, string value) {
        base.Add(key.ToLower(), value);
   }

Quote:
}



Wed, 06 Oct 2004 05:49:02 GMT  
 Override become Overload?
Hello Qing,

It is Override but not Overload. The compiler will trade it as an Override
method, never mind which prototype you select in the IntelliSenese (in fact
they are same). IntelliSenese only supplies a prompt in the Editor mode of
the IDE, and the Code is generated by the compiler. If the compiler
encounters the "override" keyword it will trade it as an Override method.
In a word, you can select any one of them and the results are same.

Best regards,

Lion Shi, MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2001 Microsoft Corporation. All rights
reserved.
--------------------
    Content-Class: urn:content-classes:message


    Subject: Override become Overload?
    Date: Fri, 19 Apr 2002 14:49:02 -0700
    Lines: 30

    MIME-Version: 1.0
    Content-Type: text/plain;
        charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit
    X-Newsreader: Microsoft CDO for Windows 2000
    X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    Thread-Index: AcHn7AUH4F/eXq9zTQWZbSDkGawV1g==
    Newsgroups: microsoft.public.dotnet.languages.CSharp
    NNTP-Posting-Host: TKMSFTNGXA04 10.201.232.163
    Path: cpmsftngxa08!cpmsftngxa06!cpmsftngxa09
    Xref: cpmsftngxa08 microsoft.public.dotnet.languages.csharp:55260
    X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

    I have a dictionary class named TestDictionary that is
    derived from StringDictionary. Within TestDictionary, I
    override the Add(string key, string value) method. The
    class compiles fine and works fine. But one thing bothers
    me: When I use the Add() method of TestDictionary class in
    Visual Studio, Intelisense would show that there are two
    overloaded Add() methods available:

       void TestDictionary.Add(string key, string value)
       void StringDictionary.Add(string key, string value)

    Why is this the case? Since the TestDictionary.Add()
    overrides the StringDictionary.Add(), shouldn't it be that
    only TestDictionary.Add() be available?

    Since both two methods has the same signature, if both are
    available, how could CLR know which one I intend to use?

    Following is the code. Any insight are appreciated.

    using System;
    using System.Collections.Specialized;
    public class TestDictionary:StringDictionary {
       public TestDictionary(){}
       public override void Add(string key, string value) {
        base.Add(key.ToLower(), value);
       }
    }



Sat, 09 Oct 2004 16:59:24 GMT  
 Override become Overload?
Thanks a lot for the clarification.

Quote:
>-----Original Message-----
>Hello Qing,

>It is Override but not Overload. The compiler will trade
it as an Override
>method, never mind which prototype you select in the

IntelliSenese (in fact
Quote:
>they are same). IntelliSenese only supplies a prompt in
the Editor mode of
>the IDE, and the Code is generated by the compiler. If
the compiler
>encounters the "override" keyword it will trade it as an
Override method.
>In a word, you can select any one of them and the results
are same.

>Best regards,

>Lion Shi, MCSE, MCSD
>Microsoft Support Engineer

>This posting is provided "AS IS" with no warranties, and
confers no rights.
>You assume all risk for your use.  2001 Microsoft

Corporation. All rights
Quote:
>reserved.
>--------------------
>    Content-Class: urn:content-classes:message


>    Subject: Override become Overload?
>    Date: Fri, 19 Apr 2002 14:49:02 -0700
>    Lines: 30
>    Message-ID: <49c401c1e7ec$050709d0


Quote:
>    MIME-Version: 1.0
>    Content-Type: text/plain;
>            charset="iso-8859-1"
>    Content-Transfer-Encoding: 7bit
>    X-Newsreader: Microsoft CDO for Windows 2000
>    X-MimeOLE: Produced By Microsoft MimeOLE
V5.50.4910.0300
>    Thread-Index: AcHn7AUH4F/eXq9zTQWZbSDkGawV1g==
>    Newsgroups: microsoft.public.dotnet.languages.csharp
>    NNTP-Posting-Host: TKMSFTNGXA04 10.201.232.163
>    Path: cpmsftngxa08!cpmsftngxa06!cpmsftngxa09
>    Xref: cpmsftngxa08

microsoft.public.dotnet.languages.csharp:55260

- Show quoted text -

Quote:
>    X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

>    I have a dictionary class named TestDictionary that
is
>    derived from StringDictionary. Within TestDictionary,
I
>    override the Add(string key, string value) method.
The
>    class compiles fine and works fine. But one thing
bothers
>    me: When I use the Add() method of TestDictionary
class in
>    Visual Studio, Intelisense would show that there are
two
>    overloaded Add() methods available:

>       void TestDictionary.Add(string key, string value)
>       void StringDictionary.Add(string key, string value)

>    Why is this the case? Since the TestDictionary.Add()
>    overrides the StringDictionary.Add(), shouldn't it be
that
>    only TestDictionary.Add() be available?

>    Since both two methods has the same signature, if
both are
>    available, how could CLR know which one I intend to
use?

>    Following is the code. Any insight are appreciated.

>    using System;
>    using System.Collections.Specialized;
>    public class TestDictionary:StringDictionary {
>       public TestDictionary(){}
>       public override void Add(string key, string value)
{
>            base.Add(key.ToLower(), value);
>       }
>    }

>.



Sat, 09 Oct 2004 22:17:03 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Calling overloaded function in base from another overload in a derived class

2. Override & Overload ?

3. STL in managed C++ crashing in malloc.c and keeping chars from becoming SBytes

4. CTreeCtrl (almost) becomes invisible

5. how to become a great C programmer?

6. content that tentative definition becomes pure reference?

7. how can stdin ever become empty?

8. I became a C guru in 24 seconds !

9. Anytime this would become infinite loop?

10. How long does it take to become a productive programmer

11. Count becomes random in loop

12. Y2K Is Rapidly Becoming an Untouchable Problem

 

 
Powered by phpBB® Forum Software