articles

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

Explicit and Implicit interface Implementation in c#.

Devesh Omar3715 30-May-2014

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


Updated 17-Jul-2019
I am Software Professional

Leave Comment

Comments

Liked By