OK so I admit right off the top that this is a bit screwy … but it does serve a logical purpose. I’m using C# for a current project and I’m trying to find a way to override a member variable in a derived class, but access the overridden variable in a base class method. To make things more “entertaining” it would be preferable if the overridden member variable was static (this is NOT shown in the example code below).
Here is my sample code:
class baseclass
{
protected string[] array = null;
public string method()
{
string str = "";
foreach (string x in this.array)
{
str += x + " ";
}
return str;
}
}
class subclass1 : baseclass
{
new string[] array = new string[]
{
"class1value1",
"class1value2",
"class1value3",
"class1value4"
};
}
class subclass2 : baseclass
{
new string[] array = new string[]
{
"class2value1",
"class2value2",
"class2value3",
"class2value4"
};
}
Any thoughts as to why this doesn't work and a way to get around it?