The explicit reference conversions are:
object
to any reference-type.S
to any class-type T
, provided S
is a base class of T
.S
to any interface-type T
, provided S
is not sealed and provided S
does not implement T
.S
to any class-type T
, provided T
is not sealed or provided T
implements S
.S
to any interface-type T
, provided S
is not derived from T
.S
with an element type SE
to an array-type T
with an element type TE
, provided all of the following are true:
S
and T
differ only in element type. In other words, S
and T
have the same number of dimensions.SE
and TE
are reference-types.SE
to TE
.S
to a statically ranked array-type T
, provided S
and T
have the same element type.System.Array
to any array-type.System.Delegate
to any delegate-type.System.ICloneable
to any array-type or 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 argument must be null
or the actual type of the object referenced by the source argument must be a type that can be converted to the destination type by an implicit reference conversion (§6.1.4). If an explicit reference conversion fails, an InvalidCastException
is thrown.
Reference conversions, implicit or explicit, never change the referential identity of the object being converted. In other words, while a reference conversion may change the type of a value, it never changes the value itself.