fork download
  1. using System;
  2.  
  3. interface A { void Foo(); }
  4. interface B { void Foo(); }
  5. interface C { void Foo(); }
  6.  
  7. class D : A, B, C {
  8. public void Foo() { Console.WriteLine("pub fn"); }
  9. void A.Foo() { Console.WriteLine("spec fun A"); }
  10. void B.Foo() { Console.WriteLine("spec fun B"); }
  11. }
  12.  
  13. public class Test
  14. {
  15. public static void Main()
  16. {
  17. var c = new D();
  18. c.Foo();
  19.  
  20. ((A)c).Foo();
  21. ((B)c).Foo();
  22. ((C)c).Foo();
  23.  
  24. // The call is ambiguous between the following methods or properties: `AExtensions.FooMeTwice(this A)' and `BExtensions.FooMeTwice(this B)'
  25. // c.FooMeTwice();
  26.  
  27. Console.WriteLine("Using extension:");
  28. ((A)c).FooMeTwice();
  29. ((B)c).FooMeTwice();
  30. }
  31. }
  32.  
  33. public static class AExtensions
  34. {
  35. internal static void FooMeTwice(this A a) {
  36. a.Foo();
  37. a.Foo();
  38. }
  39. }
  40.  
  41.  
  42. public static class BExtensions
  43. {
  44. internal static void FooMeTwice(this B b) {
  45. Console.Write("What: ");
  46. b.Foo();
  47. }
  48. }
  49.  
  50.  
Success #stdin #stdout 0.02s 15708KB
stdin
Standard input is empty
stdout
pub fn
spec fun A
spec fun B
pub fn
Using extension:
spec fun A
spec fun A
What: spec fun B