The following code:
class Program
{
static P1 p = new P1();
static void Main(string[] args)
{
var t = new P2();
p = t;
p.DoWork();
t.DoWork();
Console.ReadLine();
}
}
public class P1
{
public void DoWork()
{
Console.WriteLine("Test1");
}
}
public class P2: P1
{
new public void DoWork()
{
Console.WriteLine("Test2");
}
}
Will print out:
Test1
Test2
Is there anyway to force the call p.DoWork() to use the implementation in the P2 class. In reality the class P1 is in a third party compiled assembly so I can't modify any of the code for the P1 class. Normally I would just add the virtual keyword to P1 but this isn't possible.