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?