I have the following interface and class:
interface IMyInterface
{
void A();
void B()
{
Console.WriteLine("B");
}
}
class MyClass : IMyInterface
{
public void A()
{
Console.WriteLine("A");
}
}
I'd like to instantiate MyClass and call B() like so:
MyClass x = new MyClass();
x.B();
However, this doesn't work since MyClass does not contain a definition for 'B'. Is there anything I can add to MyClass so this code calls the default implementation of B() in IMyInterface?
I understand the code below works, but I don't want to change the data type from MyClass to IMyInterface.
IMyInterface x = new MyClass();
x.B();