ECMA-334 C# Language Specification13.2.3: Explicit reference conversions |
The explicit reference conversions are:
reference-type. class-type S to any class-type T, provided S is a base class of T. class-type S to any interface-type T, provided S is not sealed and provided S does not implement T. interface-type S to any class-type T, provided T is not sealed or provided T implements S. interface-type S to any interface-type T, provided S is not derived from T. array-type S with an element type SE to an array-type T with an element type TE, provided all of the following are true: reference-types. array-type. delegate-type. The explicit reference conversions are those conversions between reference-types that require run-time checks to ensure they are correct.
For an explicit reference conversion to succeed at run-time, the value of the source operand must be null, or the actual type of the object referenced by the source operand must be a type that can be converted to the destination type by an implicit reference conversion (13.1.4). If an explicit reference conversion fails, a System.InvalidCastException is thrown.
Reference conversions, implicit or explicit, never change the referential identity of the object being converted.