Created
April 1, 2015 08:47
-
-
Save smudge202/49d36984c58f35e7ac38 to your computer and use it in GitHub Desktop.
How did I not know this!?
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
// What is printed? | |
// 1) I am A | |
// 2) I am B | |
// 3) I am overriden B | |
// 4) None - Compiler error; Ambiguous call | |
static void Main(string[] args) | |
{ | |
var implement = new Implementation(); | |
var overloads = new A(); | |
overloads.Method(implement); | |
Console.ReadKey(); | |
} | |
private interface I1 { } | |
private interface I2 { } | |
private class Implementation : I1, I2 { } | |
private class A : B | |
{ | |
public void Method(I2 overload2) | |
{ | |
Console.WriteLine("I am A"); | |
} | |
public override void Method(I1 overload1) | |
{ | |
Console.WriteLine("I am overriden B"); | |
} | |
} | |
private class B | |
{ | |
public virtual void Method(I1 overload1) | |
{ | |
Console.WriteLine("I am B"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment