It's not entirely clear what you are trying to do, but as far as I understand your question, you want to change the behavior of M1()
, which is inherited by class Y
, by a different static method M2()
. This isn't possible, if all methods involved are static, but you can yield the desired effect if you declare M1()
as non-static. This might be done this way:
public class X
{
public Boolean M1 (Int32 x1)
{
return M2 (x1);
}
public virtual Boolean M2 (Int32 x2)
{
return M3 (x2);
}
public static Boolean M3 (Int32 x2)
{
return x2 >= 0;
}
}
public class Y : X
{
public override Boolean M2 (Int32 x2)
{
return M3 (x2);
}
public static new Boolean M3 (Int32 x2)
{
return x2 < 0;
}
}
Here's a test case:
Boolean fTest1 = new X ().M1 (1);
Boolean fTest2 = new Y ().M1 (1);
Console.Write ("{0} {1}", fTest1, fTest2);
This will output:
True False
So the wrapper method M2()
, which calls the static method M3()
in X
is virtual
and can be overridden in Y
, calling a different static method M3()
. Hence, if you're using an instance of the derived class Y
, the call to M2()
inside the inherited method M1()
is directed to the M2()
method overridden inside Y
, which in turn calls the other M3()
, with the desired change of behavior - in this example, the result is the inverse boolean value.