Explicit and Implicit interface Implementation in c#


Consider the code below.

Public interface  IstringInterface

{               String str {get;}


Public class StringClassIstringInterface

{               //Implicit implementation

Public string str

{               Return “Implicit interface Implementation” ;


//explicit implemenatation

Public string IstringInterface.str

{               Return “Explicit interface Implementation” ;




{ StringClass obj = new StringClass();


Obj.str                    // work fine   Calling way 1

(IstringInterface (Obj)).str // works fine  calling way 2


Obj.str// not works  Calling way 1

(IstringInterface (Obj)).str // // works fine  calling way 2


For implicit implementation Calling way 1 and Calling way 2 works fine

Here, from yellow line, if we will use Explicit implementation then we are not able to call the method directly, only calling way 2 work

  Modified On Jul-17-2019 10:19:11 AM

Leave Comment