Eric Bergman-Terrell's Blog

.NET Programming Tip: How can a Class Implement Multiple Interfaces Containing Methods with Identical Signatures?
October 4, 2010

For example, you have two interfaces (I1 & I2) that both contain a Send method with the same signature (identical method name, same return type, same argument types in the same order:

public interface I1
{
int Send(int id);
}

public interface I2
{
int Send(int id);
}

If you don't care which interface was used to make the call to the Send method, just implement the method:

public class c1 : I1, I2
{
int Send(int id)
{
return 0;
}
}

If you do care about which interface was used to make the Send call, use Explicit Interface Implementation by specifying the interface name before the method name (I1.Send, I2,Send):

public class c1 : I1, I2
{
int I1.Send(int id)
{
return 1;
}

int I2.Send(int id)
{
return 2;
}
}

In this case (when using Explicit Interface Implementation) the methods cannot be declared as public, although they are public (they can be called from code outside of the class). In other words, they're public with respect to the interface, but not with respect to the class.

Keywords: Interfaces, Explicit Interface Implementation

Reader Comments

Comment on this Blog Post

Recent Posts

TitleDate
.NET Public-Key (Asymmetric) Cryptography DemoJuly 20, 2025
Raspberry Pi 3B+ Photo FrameJune 17, 2025
EBTCalc (Android) Version 1.53 is now availableMay 19, 2024
Vault 3 Security EnhancementsOctober 24, 2023
Vault 3 is now available for Apple OSX M2 Mac Computers!September 18, 2023
Vault (for Desktop) Version 0.77 ReleasedMarch 26, 2023
EBTCalc (Android) Version 1.44 is now availableOctober 12, 2021