Given two interfaces:
interface I1 {
int Foo();
}
interface I2 {
void Foo();
}
And a class:
class Test : I1, I2 {
int I1.Foo() {
Console.WriteLine("I1.Foo");
return default(int);
}
public void Foo() {
Console.WriteLine("I2.Foo");
}
}
How can I extend the interface I2 with I1 by keeping the methods named Foo?
I tried the following code but it doesn’t compile:
interface I1 {
int Foo();
}
interface I2 : I1 {
void I2.Foo();
}
class Test : I2 { /* same code */ }
It is unclear in the example what explicitly declaring
I2.Foo()in the interface itself would accomplish if it were permitted. The specification (s. 13.4.1) allows the struct or class implementing an interface to declare an explicit member implementation. (Interfaces cannot declare any implementation, explicit or otherwise).Thus, suppose we have defined:
Then the following driver shows the effect of the explicit interface method implementation.