In my project, I found a strange situation that seems completely valid in C #, because I don't have compile-time errors.
A simplified example is as follows:
using System; using System.Collections.Generic; namespace Test { interface IFoo { void FooMethod(); } class A { public void FooMethod() { Console.WriteLine("implementation"); } } class B : A, IFoo { } class Program { static void Main(string[] args) { IFoo foo = new B(); foo.FooMethod(); } } }
Such code is compiled. However, note that A not IFoo , and B does not implement IFoo methods. In my case, by chance (after refactoring), A has a method with the same signature. But why does A know how to implement the FooMethod interface? A does not even know that IFoo exists.
For me, this design is dangerous. Since every time I implement some interface, I have to check if each method in this interface does not interfere with the methods of the base class.
If it is a "pure C # function"? How it's called? Did I miss something?
c # interface
javapowered Feb 05 '13 at 9:16 2013-02-05 09:16
source share