Home > DeveloperSection > Articles > Explicit and Implicit interface Implementation in c#.

Explicit and Implicit interface Implementation in c#.


ASP.Net ASP.Net 
Ratings:
0 Comment(s)
 1718  View(s)
Rate this:

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” ;

}

}

Main()

{ StringClass obj = new StringClass();

//Implicit

Obj.str                    // work fine   Calling way 1

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

//Explicit

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


Don't want to miss updates? Please click the below button!

Follow MindStick