Skip to content

Instantly share code, notes, and snippets.

@smudge202
Created April 1, 2015 08:47
Show Gist options
  • Save smudge202/49d36984c58f35e7ac38 to your computer and use it in GitHub Desktop.
Save smudge202/49d36984c58f35e7ac38 to your computer and use it in GitHub Desktop.
How did I not know this!?
// 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