Inheritance from multiple interfaces with the same method name.

I just show you a piece of code, that is self-explanatory:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CsharpConsoleApplication
{
    public interface ITest
    {
        void Test();
    }
    public interface ITest2
    {
        void Test();
    }
    public class Dual : ITest, ITest2
    {
        void ITest.Test()
        {
            Console.WriteLine("ITest.Test");
        }
        void ITest2.Test()
        {
            Console.WriteLine("ITest2.Test");
        }
    }
    class Program
    {
        private static void Main(string[] args)
        {
            var d = new Dual();
            ITest test = d;
            test.Test();
            ((ITest2)test).Test();
        }
    }
}

When using explicit interface implementation the functions are not public in the class. So first, we need either assign this object to interface variable or cast it to the interface type.

Share this post:Tweet about this on TwitterShare on Facebook0Share on LinkedIn0Share on Google+0Share on Reddit0Email this to someoneDigg this