Following snippet wouldn't compile. With following error:
Cannot implicitly convert type 'Container<ChildClass>' to 'Container<BaseClass>'
class BaseClass {}
class ChildClass : BaseClass {}
class Container<T> where T : BaseClass {}
class Program {
static void Main() {
// why doesn't this work?
Container<BaseClass> obj = new Container<ChildClass>();
}
}
Is this by design? If it is, what is the reason?