Explicit Interface Member Implementation C# with Example



Explicit Interface Member Implementation C# with Example

 using System;

namespace CSharpInterface
{
	interface IDisplay { void Display(string s); }
	
    public class BaseClass : IDisplay
    {
        void IDisplay.Display(string s)
        {
            Console.WriteLine("IDisplay.Display() Called {0}", s);
        }
		
		public void CallDisplay()
		{
			//Display("This is not possible. Raise Compile Error.");
			//this.Display("This is not possible. Raise Compile Error.");
			
			((IDisplay)this).Display("((IDisplay)this).Display()");
		}
    }

    class MultipleInterfaceImplementation
    {
        public static void Main(string[] args)
        {
            BaseClass obj = new BaseClass();
			obj.CallDisplay();
        }
    }
}
 

0 Comment's

Comment Form

Submit Comment