[Mono-list] An inheritance dilemma

Francisco M. Marzoa fmmarzoa at gmx.net
Mon Nov 22 08:53:08 EST 2010


Hello Abe,

I'm grateful for your help, but this will not work. Among other things
you're getting into an infinite recursion loop calling B.SampleMethod()
from B.SampleMethod()...

Regards,

El 21/11/10 19:49, Abe Gillespie escribió:
> Don't call base in SampleMethod -> this skips your override /
> virtualization.  SampleMethod should be:
>
>         public override void SampleMethod () {
>             SampleMethod();
>             Console.WriteLine (this.BuildString());
>         }
>
> Note that you can also do:
>
> A a = new B();
> a.SampleMethod();
>
> and you'll get B's implementation of SampleMethod.
>
> Good luck.
> -Abe
>   



More information about the Mono-list mailing list