CSharp - What is the output: implement the interface explicitly


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();
                                   //Interface1 ob6 = myClassOb;


Click to view the answer

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;

Alternatively, you can use the following line of code to get the same output:


Related Quiz