© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
12 replies
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(); }
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Covariant return type properties
C#CC# / help
2y ago
Differing covariant arrays [Answered]
C#CC# / help
4y ago
❔ You cannot use a covariant type parameter as a generic type constraint for interface methods.
C#CC# / help
3y ago
interface
C#CC# / help
3y ago