#54: Invoking Explicit Interface-Cannot Invoke with Class Instance,but requires Interface Instance

You cannot Invoke Explicit Interface with Class Instance,You require Interface Instance to call the Explicit Interface

 class Sample:ITest
 {
 //Interface Defined Explicitly
 void ITest.Test()
 {
 Console.WriteLine("Hello");
 }
 }

To Invoke the explicit interface,you need Interface Instance,not the class instance

/*You cannot invoke Explicit Interface with Class Instance but the 
 Interface instance. ITest is the inetrface instance
 */
 ITest s1 = new Sample();
 s1.Test();

One thought on “#54: Invoking Explicit Interface-Cannot Invoke with Class Instance,but requires Interface Instance

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