Explicit and Implicit interface Implementation in c#
Consider the code below.
Public interface IstringInterface
{ String str {get;}
}
Public class StringClass: IstringInterface
{ //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
Leave Comment