Multiple Interface Reference From Same Class C# with Example



Multiple Interface Reference From Same Class C# with Example

 using System;

namespace CSharpInterface
{
	interface IDisplay1 { void Display(string s); }
	interface IDisplay2 { void Display(string s); }
	
    public class BaseClass : IDisplay1, IDisplay2
    {
        public void Display(string s)
        {
            Console.WriteLine("Called via {0}", s);
        }
    }

    class MultipleInterfaceImplementation
    {
        public static void Main(string[] args)
        {
            BaseClass obj = new BaseClass();
			IDisplay1 i1 = (IDisplay1)obj; 	//Get reference to IDisplay1
			IDisplay2 i2 = (IDisplay2)obj; 	//Get reference to IDisplay2
			
            obj.Display("Base Class");
			i1.Display("IDisplay1 Interface");
			i2.Display("IDisplay2 Interface");
        }
    }
}
 

0 Comment's

Comment Form

Submit Comment