What if all the interfaces contain same method with same signature?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh KumarRank #91 · 22.9K reputationPosted Oct 14, 2022, 1:47 AM EDT
You need to implement it will explicitly by interface name thats call as Explicit Interface implementation.
https://www.c-sharpcorner.com/article/implementing-multiple-interfaces-with-the-same-method-signature-in-c-sharp/
https://www.c-sharpcorner.com/UploadFile/19b1bd/implicit-and-explicit-interface-implementation/
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Oct 14, 2022, 3:07 AM EDT
Hello Uday,
you can do explicit interface method implementation as below.
interface IDog{ //identify vehicle by model, make, year string IdentifySelf(); } interface ICat{ //identify robot by name int IdentifySelf(); } class Animal: IDog, ICat { string IDog.IdentifySelf() // Explicit interface method implementation { return "Dog"; } int ICat.IdentifySelf() // Explicit interface method implementation { return 5; } } class Program { static void Main(string[] args) { Animal animal= new Animal(); ((IDog)animal).IdentifySelf(); ((ICat)animal).IdentifySelf(); Console.ReadLine(); } }https://www.c-sharpcorner.com/article/explicit-interface-implementation/