C# LANGUAGE SPECIFICATION
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 (§11.3.2).
Unboxing conversions are described further in §4.3.2.
6.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 §6.4.4.
6.3 Standard conversions
The standard conversions are those pre-defined conversions that can occur as part of a user-defined conversion.
6.3.1 Standard implicit conversions
The following implicit conversions are classified as standard implicit conversions:
Identity conversions (§6.1.1)
Implicit numeric conversions (§6.1.2)
Implicit reference conversions (§6.1.4)
Boxing conversions (§6.1.5)
Implicit constant expression conversions (§6.1.6)
The standard implicit conversions specifically exclude user-defined implicit conversions.
6.3.2 Standard explicit conversions
The standard explicit conversions are all standard implicit conversions plus the subset of the explicit conversions for which an opposite standard implicit conversion exists. In other words, if a standard implicit conversion exists from a type A to a type B, then a standard explicit conversion exists from type A to type B and from type B to type A.
6.4 User-defined conversions
C# allows the pre-defined implicit and explicit conversions to be augmented by user-defined conversions. User-defined conversions are introduced by declaring conversion operators (§10.9.3) in class and struct types.
6.4.1 Permitted user-defined conversions
C# permits only certain user-defined conversions to be declared. In particular, it is not possible to redefine an already existing implicit or explicit conversion. A class or struct is permitted to declare a conversion from a source type S to a target type T only if all of the following are true:
S and T are different types.
Either S or T is the class or struct type in which the operator declaration takes place.
Neither S nor T is object or an interface-type.
T is not a base class of S, and S is not a base class of T.
The restrictions that apply to user-defined conversions are discussed further in §10.9.3.
6.4.2 Evaluation of user-defined conversions
102Copyright Microsoft Corporation 1999-2003. All Rights Reserved.