打印本文 打印本文 关闭窗口 关闭窗口
13.2 Explicit conversions
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1884  更新时间:2009/4/25 0:44:45  文章录入:mintao  责任编辑:mintao
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 (?3.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. [Note: In other words, while a reference conversion may change
the type of the reference, it never
changes the type or value of the object being referred to. end note]
13.2.4 Unboxing conversions
An unboxing conversion permits an explicit conversion from type object or
System.ValueType to any
value-type, or from any interface-type to any value-type that implements
the interface-type. An unboxing
operation consists of first checking that the object instance is a boxed
value of the given value-type, and then
copying the value out of the instance. A struct can be unboxed from the
type System.ValueType, since
that is a base class for all structs (?8.3.2).
Unboxing conversions are described further in ?1.3.2.


13.2.5 User-defined explicit conversions
A user-defined explicit conversion consists of an optional standard
explicit conversion, followed by
execution of a user-defined implicit or explicit conversion operator,
followed by another optional standard
explicit conversion. The exact rules for evaluating user-defined
conversions are described in ?3.4.4.

上一页  [1] [2] 

打印本文 打印本文 关闭窗口 关闭窗口