Explicit Interface Implementation : Explicit Interface Implementation « Class « C# / CSharp Tutorial






using System;

interface InterfaceOne
{
    void Execute();
}

interface InterfaceTwo
{
    void Execute();
}

class MyImplementation: InterfaceOne, InterfaceTwo
{
    void InterfaceOne.Execute() 
    {
        Console.WriteLine("InterfaceOne.Execute implementation");
    }
    void InterfaceTwo.Execute()
    {
        Console.WriteLine("InterfaceTwo.Execute implementation");
    }
}

class MainClass
{
    public static void Main()
    {
        MyImplementation MyImplementation = new MyImplementation();
        
        InterfaceOne InterfaceOne = (InterfaceOne) MyImplementation;
        InterfaceOne.Execute();
        
        InterfaceTwo InterfaceTwo = (InterfaceTwo) MyImplementation;
        InterfaceTwo.Execute();
    }
}
InterfaceOne.Execute implementation
InterfaceTwo.Execute implementation








7.34.Explicit Interface Implementation
7.34.1.Interface member hiding
7.34.2.Explicit Interface Implementation
7.34.3.Explicit interface implementation and its own implementation
7.34.4.Explicitly implement an interface member
7.34.5.Use explicit implementation to remove ambiguity