One interface can inherit another. The syntax is the same as for inheriting classes. When a class implements an interface that inherits another interface, it must provide implementations for all the members defined within the interface inheritance chain. Following is an example:
// One interface can inherit another. using System; public interface A { void meth1(); void meth2(); } // B now includes meth1() and meth2() -- it adds meth3(). public interface B : A { void meth3(); } // This class must implement all of A and B class MyClass : B { public void meth1() { Console.WriteLine("Implement meth1()."); } public void meth2() { Console.WriteLine("Implement meth2()."); } public void meth3() { Console.WriteLine("Implement meth3()."); } } class IFExtend { public static void Main() { MyClass ob = new MyClass(); ob.meth1(); ob.meth2(); ob.meth3(); } }
As an experiment you might want to try removing the implementation for meth1( ) in MyClass. This will cause a compile-time error. As stated earlier, any class that implements an interface must implement all methods defined by that interface, including any that are inherited from other interfaces.