Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Interface with base class
Message
De
05/08/2009 04:25:02
 
 
À
04/08/2009 23:52:27
Information générale
Forum:
ASP.NET
Catégorie:
Programmation orienté objet
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01416072
Message ID:
01416159
Vues:
56
Hi Bonnie,

I knew that the compiler would make an implicit cast in this case - just thought it would make the same implicit cast for the interfaces example. I don't see why not - AFAICS no strong-typing rules are being broken. If the compiler accepts that DerivedClass 'is a' BaseClass in one case why not in the other?

IAC, in the real case I don't think this option is open to me. I'm working with the EntityFramework and 'Parent' is acutally an instance of a class derived from EntityObject so the Interface I'd need is:
public interface ITest
 {
      EntityObject Parent { get; }
 }
Oh well, best,
Viv


>I think you want this (and it should work fine):
>
>
>    public class Test : ITest
>    {
>        public BaseClass Parent
>        {
>            get {return new DerivedClass(); }
>        }
>    }
>
>
>~~Bonnie
>
>
>>I thought I'd used this sort of construct before. But the compiler insists that the type of Parent in Test must be BaseClass.
public interface ITest
>>    {
>>        BaseClass Parent { get; }
>>    }
>>
>>    public class BaseClass {}
>>
>>    public class DerivedClass : BaseClass{}
>>
>>    public class Test : ITest
>>    {
>>        public DerivedClass Parent
>>        {
>>            get {return new DerivedClass(); }
>>        }
>>    }
Am I cracking up?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform