Overriding newbie question.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
A control has
privtae void MethodA()
{

//etc

MethodB();
{

// NO CODE, THE PROGRAM WHICH WILL INHERIT THIS CONTROL WILL PROVIDE THE CODE.
}

I hope this make sense, I have tried using virtual and override without success the control always calls its own methodB

any help/thoughts will be appericated.

TIA
 
The base and derived class method signatures for method B must match exactly so:

class Foo
{
public virtual int MyMethod(double d)
{
}
}

class Bar : Foo
{
public override int MyMethod(double d)
{
// this one will not always get called
}
}

The other fundemental thing is this will only work if the method is being called on a derived class object. So for the above example:

Foo f = new Foo();
f.MyMethod(2.0); // this will call Foo.MyMethod

f = new Bar();
f.MyMethod(2.0); // this will call Bar.MyMethod

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi,
A control has
privtae void MethodA()
{

//etc

MethodB();
{

// NO CODE, THE PROGRAM WHICH WILL INHERIT THIS CONTROL WILL PROVIDE THE CODE.
}

I hope this make sense, I have tried using virtual and override without success the control always calls its own methodB

any help/thoughts will be appericated.
 
Back
Top