colinfang
colinfang

Reputation: 21727

which overloaded method would it use?

for example we have

     BaseClass myBaseObject
     InheritedClass myInheritedObject

and 2 overloaded methods

     void Do(BaseClass tmp)
        { DoA();}
     void Do(InheritedClass tmp)
        { DoB();}

What would this do?

     Do((BaseClass) myInheritedObject);

And is it common technique to put DoA() under BaseClass, and DoB() under InheritedClass and override DoA(), and merge the 2 Do() into 1?

        void Do(BaseClass tmp)
           {return tmp.DoA()}

Upvotes: 0

Views: 62

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500675

The first - the second overload isn't applicable, because the compile-time type of the argument is BaseClass instead of InheritedClass, and there's no implicit conversion from BaseClass to InheritedClass.

Upvotes: 2

Related Questions