According to the documentation (Explicit conversions) you can cast from a base type to a derived type.
Since null
is a valid value for all reference types, as long as the cast route exists you should be fine.
object
null → TestClass
null works as object
is a superclass to all reference types.
However, if you try string
null → TestClass
null (Assuming TestClass
is not a subtype of string
), you will find a compilation error as TestClass
is not a derived type of string
.