I don't understand why this doesn't work:
Classes:
public abstract class BaseObj
{
public bool IsValid => GetValidationErrors().Count == 0;
}
public class BaseObjWithId: BaseObj
{
public int Id { get; set; }
}
public class BaseReference<T> : BaseObj where T : BaseObjWithId
{
public T ObjReference { get; set; }
}
public class Foo: BaseObjWithId
{
public string Name{get;set;}
}
public class FooRef : BaseReference<Foo>
{
}
Code-Statement:
BaseReference<BaseObjWithId> foo= new FooRef();
Error CS0029 Cannot implicitly convert type...
This works:
BaseReference<Foo> foo= new FooRef();
But I don't understand why, because Foo is a BaseObjWithId...
Thank you for your explanation