0

I have the below code to implement two interface with the same name and signature.

interface L1 { 
   void printresult();
}

interface L2 { 
   void printresult(); 
}

public class test : L1, L2
{
    void L1.printresult()
    {
        Console.WriteLine("print the result");
    }

    void L2.printresult()
    {
        Console.WriteLine("print the result");
    }
}

How I can access the L2.printresult() from the program?

I tried test t1=new test();

but its not working.

How to access the methods of test and why its not accessible in the above way?

Alex K.
  • 171,639
  • 30
  • 264
  • 288
Tom Cruise
  • 1,395
  • 11
  • 30
  • 58
  • You are explicitly implementing the interfaces, you need to cast `t1` to `L1` or `L2` to access the members of the interfaces: `L1 l1 = t1; l1.printresult();` – Yacoub Massad Sep 29 '16 at 11:09
  • If you want to call `L2.printresult()`, you have to access `t1` as `L2`: `((L2)t1).printresult()`. See [duplicate](http://stackoverflow.com/questions/15076176/how-to-call-a-particular-explicitly-declared-interface-method-in-c-sharp). – CodeCaster Sep 29 '16 at 11:09

0 Answers0