I know it's not possible to cast derived lists (why not is nicely explained here), but what about ImmutableArrays as they cannot be changed casting should be valid, right?
I would expect this to work:
class Animal {} class Dog : Animal {} ImmutableArray<Dog> dogs = ImmutableArray.Create<Dog>(new Dog()); ImmutableArray<Animal> animals = (ImmutableArray<Animal>) dogs; ImmutableArray<Dog> dogsBack = (ImmutableArray<Dog>) animals;
dogsas if it containedAnimalinstances or addDoginstances toanimalson creation?