#53 Mutiple Interface with Same Contract

Let’s Assume we have two interface with same contract:

interface ITest
 {
 void Test(); //Same Contract as of other interface
 }
interface ITest1
 {
 void Test(); //Same Contract as of other interface
 }

To define both the Interface with same contract  in a class,you have to define Interface Explicitly without Access Modifier.

class Sample:ITest,ITest1
 {
 void ITest.Test()
 {
 Console.WriteLine("Hello");
 }
 void ITest1.Test()
 {
 Console.WriteLine("Hello1");
 }
 } 

To invoke the specific Contract,

//You cannot invoke Explicit Interface with Class Instance.
 ITest s1 = new Sample();
 s1.Test();
 ITest1 s2 = new Sample();
 s2.Test();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s