Overload resolution and virtual methods

前端 未结 5 640
臣服心动
臣服心动 2020-11-28 11:15

Consider the following code (it\'s a little long, but hopefully you can follow):

class A
{
}

class B : A
{
}

class C
{
    public virtual void Foo(B b)
            


        
5条回答
  •  执念已碎
    2020-11-28 11:56

    I think it is because in case of a non-virtual method the compile time type of the variable on which the method is invoked is used.

    You have the Foo method which is non-virtual and hence that method is called.

    This link has very good explanation http://msdn.microsoft.com/en-us/library/aa645767%28VS.71%29.aspx

提交回复
热议问题