I have three classes with a common parent. Let say that the parent is Animal, and the children - Dog, Cat and Parrot.
And I have one observable collection containing a collection of animals that the user is working with. The collection contains all animals of the same type - the user only works with all dogs or cats or all parrots.
So, I declared the animals ObservableCollection<Animal> , and depending on the userβs choice, I want to change the contents of the animal properties to ObservableCollection<Dog> or ObservableCollection<Cat> or ObservableCollection<PArrot> . Therefore, it does not matter if the user is currently working with dogs or cats, but he can choose all the actions that animals have together.
But that will not work. It seems that I cannot assign an ObservableCollection<Cat> Property of type ObservableCollection<Animal> . I think this should work because the animal is a supertype of the cat, so I can assign the cat a variable to the animal, as usual.
Why can't I do this and how to solve this problem?
user1018711
source share