inherited class instead of expected class in interface implementation

P

parez

Why should the following not compile? ( it does not)

interface ISomething
{

Apples a {get;set;}
}


public class ChilieanApples:Apples
{
}

public class Apples
{
}


Class SomethingSpecific:ISomething
{
public ChilieanApples apples {get;set;}
}
 
J

Jon Skeet [C# MVP]

Why should the following not compile? ( it does not)

Because C# doesn't support covariance of return types in terms for
interface implementation and member overriding. To override/implement
something, you have to supply exactly the same signature.

It's a pain, but that's the way it is.

Jon
 
P

parez

Because C# doesn't support covariance of return types in terms for
interface implementation and member overriding. To override/implement
something, you have to supply exactly the same signature.

It's a pain, but that's the way it is.

Jon

Thanks.
I thought I mite have missed something because i expected it to
compile.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top