If you're working with an instance of the derived class, there is no base instance
.
An example:
class A
{
public void Foo() { ... }
}
class B : A
{
public void Bar() { ... }
}
What is not possible within B
:
public void Bar()
{
// Use of keyword base not valid in this context
var baseOfThis = base;
}
You can do something like this:
public void Bar()
{
base.Foo();
}
And you can add another method like
public A GetBase()
{
return (A)this;
}
And then you can
public void Bar()
{
var baseOfThis = GetBase();
// equal to:
baseOfThis = (A)this;
}
So this GetBase()
method is probably what you want.
The punchline is: If you have an instance of B
, it inherits all properties and the non-overriden behaviour of A
, but it does not consist of an instance of B
which holds an (hidden but automatic) reference to an instance of A
. You can cast your B
instance to A
, but it remains to be an instance of B
.