Search code examples
c#.netinterfaceimplicitexplicit

Implicit <> Explicit interface


Possible Duplicates:
C#: Interfaces - Implicit and Explicit implementation
implicit vs explicit interface implementation

Hello

Can anyone explain me what the difference is between an implicit and explicit interface?

Thanks!


Solution

  • An implicit interface implementation is where you have a method with the same signature of the interface.

    An explicit interface implementation is where you explicitly declare which interface the method belongs to.

    interface I1
    {
        void implicitExample();
    }
    
    interface I2
    {
        void explicitExample();
    }
    
    
    class C : I1, I2
    {
        void implicitExample()
        {
            Console.WriteLine("I1.implicitExample()");
        }
    
    
        void I2.explicitExample()
        {
            Console.WriteLine("I2.explicitExample()");
        }
    }
    

    MSDN: implicit and explicit interface implementations