I have a class with a generic Type:
class SomeClass<T>
{
}
And two classes -> one inherits fromt the other:
class Animal
{
}
class Lion : Animal
{
}
Now I want to create a variable of "SomeClass" with the base generic and give it an object witht the inherited type as generic type, like this:
void Test()
{
SomeClass<Lion> someLion = new SomeClass<Lion>();
SomeClass<Animal> someAnimal = someLion; //Error line
}
The error is:
Cannot implicitly convert type 'VitrasUI.SomeClass' to 'VitrasUI.SomeClass'
From my understanding I should be able to convert it this way, as it works with IEnumerables, too:
void Test1()
{
IEnumerable<Lion> listLion = new List<Lion>();
IEnumerable<Animal> listAnimal = listLion;
}