Provide a detailed explanation of the approach to differentiate and implement the methods from each interface in the class, ensuring that the correct implementation is invoked when calling these methods.
Interviews3 answers
How do you handle scenarios in C# when you have the same method name defined in two interfaces, and you inherit both of these interfaces in a single class?
3 Answers
You can solved the problem using explicit interface,
So if two interface having same method name, SO in this case when a class implement two interface, we provide the implementation using interace name dot method name.
Wasim HajwanePosted Feb 16, 2024, 7:42 AM EST
use explicit Interface Implementation
interface.method
KaminmPosted Jan 25, 2024, 10:32 AM EST
Using Explicit Interface Implementation we can solve your scenario
Class A : I1, I2{
public void I1.doSomething();
public void !2.doSomething();
}
Akhil PPosted Jan 20, 2024, 10:07 PM EST
