Take the following code:
ICanQuack quack = new Duck(); var map = (object) "a map"; quack.Fly((dynamic)map);
using those types
public interface ICanFly { void Fly<T>(T map); } public interface ICanQuack : ICanFly { void Quack(); } public class Duck : ICanQuack { public void Fly<T>(T map) { Console.WriteLine("Flying using a {0} map ({1})", typeof (T).Name, map); } public void Quack() { Console.WriteLine("Quack Quack!"); } }
Compiled with C# 5 compiler against .NET 4.5.1 (the behaviour is probably the same using older compiler/framework version) this generates the following error:
Now, I have a pretty good idea what is happening under the covers (I blogged about it here) but I can't come up with a satisfying answer why?
I am guessing this situation has already been reported to Microsoft.
Take a look here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With