I have the following simple code
abstract class A
{
public abstract void Test(Int32 value);
}
class B : A
{
public override void Test(Int32 value)
{
Console.WriteLine("Int32");
}
public void Test(Double value)
{
Test((Int32)1);
}
}
When I ran this code the line Test((Int32)1) causes stack overflow due to infinite recursion. The only possible way to correctly call proper method (with integer parameter) I found is
(this as A).Test(1);
But this is not appropriate for me, because both methods Test are public and I am willing the users to be able to call both method?
Unfortunately in order to call the
A::Test(int)through aBreference some sort of cast is needed. So long as the C# compiler sees the reference throughBit will pick theB::Test(double)version.A slightly less ugly version is the following
Another thought though is have a private method with a different name that both feed into.