Created
January 20, 2022 22:52
-
-
Save ericlippert/1d64b2feefca016074150d393997e443 to your computer and use it in GitHub Desktop.
Ambiguous interfaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface I1<U> | |
{ | |
void M(U i); // generic first | |
void M(int i); | |
} | |
public interface I2<U> | |
{ | |
void M(int i); | |
void M(U i); // generic second | |
} | |
public class C3: I1<int>, I2<int> | |
{ | |
void I1<int>.M(int i) | |
{ | |
System.Console.WriteLine("c3 explicit I1 " + i); | |
} | |
void I2<int>.M(int i) | |
{ | |
System.Console.WriteLine("c3 explicit I2 " + i); | |
} | |
public void M(int i) | |
{ | |
System.Console.WriteLine("c3 class " + i); | |
} | |
} | |
public class Test | |
{ | |
public static void Main() | |
{ | |
C3 c3 = new C3(); | |
I1<int> i1_c3 = c3; | |
I2<int> i2_c3 = c3; | |
i1_c3.M(101); | |
i2_c3.M(102); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment