What is the output from the following code
using System; interface Interface1 { void ShowInterface1(); } class MyClass : Interface1 { void Interface1.ShowInterface1() { Console.WriteLine("ShowInterface1() is completed."); } } class Program { static void Main(string[] args) { MyClass myClassOb = new MyClass(); myClassOb.ShowInterface1();//Error //Interface1 ob6 = myClassOb; //ob6.ShowInterface1(); } }
There is a compilation error.
We have implemented the interface explicitly.
To access the explicit interface member, use the interface type.
To fix the error, use following lines of codes:
Interface1 ob6 = myClassOb; ob6.ShowInterface1();
Alternatively, you can use the following line of code to get the same output:
((Interface1)myClassOb).ShowInterface1();