This question gives the answer that Java\'s @Override has the C# equivalent of the override
keyword on methods. However, since Java 1.6 the @Override annotation can
There is similar functionality: explicit interface implementation.
public interface IA {
void foo();
// void bar(); // Removed method.
}
public class B : IA {
void IA.foo() {}
void IA.bar() {} // does not compile
}
The problem is that if you do this you cannot call the methods through the this
pointer (from inside the class) or through an expression that evaluates to a B
-- it is now necessary to cast to IA
.
You can work around that by making a public method with the same signature and forwarding the call to the explicit implementation like so:
public class B : IA {
void IA.foo() { this.foo(); }
public void foo() {}
}
However this isn't quite ideal, and I 've never seen it done in practice.