what is the difference between explicit interface and implicit interface implementation in c#/asp.net? in which scenario we can use the explicit interface and implicit interface implementation.
Thanks,
Pradeep
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Say you have two interfaces,
IDoStuff<T>andIDoStuff, which your class implements. They both have a method “GetStuff”, but one has the signatureT GetStuff(), and the other has the signatureobject GetStuff().The problem is that .net will not let you have two methods named the same thing that only differ on the return type. But you need to have both of these methods in your class to satisfy both interfaces. If
Tis, in fact, anobject, then you can use explicit implementation like so.Note that because
IDoStuffmandates the security requirements ofGetStuff,IDoStuff.GetStuffwill bepublic/private/protected/internalbased on that interface’s declaration.If you wanted, you could do every implantation explicitly, but the full method name for each would be
InterfaceName.MethodName, and that gets a little annoying to read and write. Usually this is only used when you want to implement a method with the same signature multiple times to satisfy several interfaces.