C#C
C#3y ago
SirCarter

❔ Covariant Interface Return

Is there some reason why this doesn't work? I understand we can get this behavior with virtual methods and inheritance, but it feels like this should work with interfaces.

interface IFooReturner { Foo GetFoo(); }
class Foo {}
class FooBar : Foo {}
class FooBarGetter : IFooReturner { FooBar GetFoo(); }


If FooBar is a Foo, this implementation should be valid no?
Was this page helpful?