public class Derived : Base
{
public override void SomeMethod() {
base.SomeMethod (); // note lower case 'b'
Console.WriteLi ne "B";
}
}
base is a keyword that allows you to invoke a method on your direct base class
Regards
Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<vr************ **@news04.bloor .is.net.cable.r ogers.com>
I have a question on calling parent class... What I want to do is: when
calling the derived class, it automatically executes the parent's method, is
it possible?
// main code:
Derived d = new Derived();
d.SomeMethod();
public class Base
{
public virtual void SomeMethod() {
Console.WriteLi ne "A";
}
}
public class Derived : Base
{
public override void SomeMethod() {
// this.parent.Som eMethod();
Console.WriteLi ne "B";
}
}
Is there a way to call the derived class and then both "A" and "B" will be
printed out?
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004
[microsoft.publi c.dotnet.langua ges.csharp]