Calling a base class' method
C#OopC# Problem Overview
In c++ I would do
class A
{
public:
virtual void stuff()
{
//something
}
};
class B : public A
public:
virtual void stuff()
{
//something2
A::stuff() //something
}
};
How would I do this in C#? I've tried
public void stuff()
{
//something2
A.stuff(); //something
}
but that doesn't work
C# Solutions
Solution 1 - C#
base
is the keyword for referencing your superclass in C#. Use:
base.stuff();
Solution 2 - C#
Use base
. Like base.stuff();
Solution 3 - C#
Just to add to the answer above, base.stuff() works, unless it's the constructor you're trying to call in which case it is called as:
class A
{
public:
public A(){}
};
class B : A
{
public B() : base()
{
}
};