I'm not even sure what it's called or even if it's possible, what I'm trying to do.
I'm hoping the code might explain it.
Each class that derives from Base has a method named oPrint, and I want to call them in the below fashion(ish) if possible.
namespace nSpace
{
class Base
{
public void Print(object val)
{
Console.WriteLine("Printing a " + val.GetType());
}
}
class Class1 : Base
{
public string val = "1";
public void oPrint()
{
Print(val);
}
}
class Class2 : Base
{
public int val = 1;
public void oPrint()
{
Print(val);
}
}
class Program
{
static void Main(string[] args)
{
Base[] reg = new Base[2];
reg[0] = new Class1();
reg[1] = new Class2();
foreach (Base r in reg)
{
r.oPrint(); // Base does not contain a definition for oPrint
}
Console.ReadKey();
}
}
}
Any help with my failings is appreciated.