Why can I only upcast a generic and not downcast it?
How is it not clear to the compiler that if my constraint says where T : BaseClass and U is derived from BaseClass that (U)objectOfTypeT is valid?
Why can I only upcast a generic and not downcast it? How is it
Share
Because it might not be valid. Consider this:
Just because they share the same base class does not mean that you can typecast one to the other.
Note that you can get around this by using the
asoperator: