-
-
Save kg/2517480 to your computer and use it in GitHub Desktop.
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
using System; | |
public interface I { | |
void Foo (); | |
} | |
public class A : I { | |
public void Foo () { | |
Console.WriteLine("A"); | |
} | |
} | |
public class B : A, I { | |
void I.Foo () { | |
Console.WriteLine("B"); | |
} | |
} | |
public static class Program { | |
public static void Main (string[] args) { | |
I i; | |
var a = new A(); | |
i = a; | |
a.Foo(); // expected: "A" | |
i.Foo(); // expected: "A" | |
var b = new B(); | |
i = b; | |
b.Foo(); // expected: "A" | |
i.Foo(); // expected: "B" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment