I have a question regarding inheritance in C#. I have a public abstract class A that defines protected virtual members. I have another abstract class B that inherits from A, and then another internal class C, inheriting from B. The first class A is in a separate namespace, and the other two are in the same namespace, but include a reference to the first.
I was trying to access the protected virtual member of A in C using base keyword, but am unable to unless I provide a method in B and then call A's protected virtual member there.
I want to know if what I was trying to do is possible, i.e. was I doing something incorrectly? Or if its not possible, then why? Thanks.
Here's the code sample :
namespace A
{
public abstract class BaseClass
{
protected virtual string GetData()
{
//code to get data
}
}
}
namespace B //includes a reference to A
{
abstract class DerivedClassA : BaseClass
{
}
internal class DerivedClassB: DerivedClassA
{
public void write()
{
base.GetData(); // results in error.
// The name 'GetData' does not exist in the current context
// and DerivedClassA does not contain a definition for 'GetData'
}
}
Got the source of the problem. Apparently, the location of the dlls that the second namespace was referring to had changed and hence, it was pointing to an outdated reference. After I updated the references from the correct location, it ran fine. Thanks all for the help.