While I try to run following code snippet, it’s executing wrong overload method. I'm confused why it does that?   [testB.TestMethod(testValue) method execute the  public double TestMethod(double value) method]
public class TestA {     public int TestMethod(int value)     {         return value;     } }  public class TestB : TestA {     public double TestMethod(double value)     {         return value;     } }  static void Main( string[] args ) {     TestB testB = new TestB();      int testValue = 3;      testB.TestMethod(testValue); }   Do you have any idea about this ?
Is there are any way to call TestA class method via the TestB instance without cast as TestA.?
But it is not happen in JAVA and C++
From the specification, under "Overload Resolution":
...and methods in a base class are not candidates if any method in a derived class is applicable (§7.6.5.1).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With