13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C#</strong> LANGUAGE SPECIFICATIONcopying the value out of the instance. A struct can be unboxed from the type System.ValueType, sincethat is a base class for all structs (§18.3.2).Unboxing conversions are described further in §11.3.2.13.2.5 User-defined explicit conversionsA user-defined explicit conversion consists of an optional standard explicit conversion, followed byexecution of a user-defined implicit or explicit conversion operator, followed by another optional standardexplicit conversion. The exact rules for evaluating user-defined conversions are described in §13.4.4.13.3 Standard conversionsThe standard conversions are those pre-defined conversions that can occur as part of a user-definedconversion.13.3.1 Standard implicit conversionsThe following implicit conversions are classified as standard implicit conversions:• Identity conversions (§13.1.1)• Implicit numeric conversions (§13.1.2)• Implicit reference conversions (§13.1.4)• Boxing conversions (§13.1.5)• Implicit constant expression conversions (§13.1.6)The standard implicit conversions specifically exclude user-defined implicit conversions.13.3.2 Standard explicit conversionsThe standard explicit conversions are all standard implicit conversions plus the subset of the explicitconversions for which an opposite standard implicit conversion exists. [Note: In other words, if a standardimplicit conversion exists from a type A to a type B, then a standard explicit conversion exists from type A totype B and from type B to type A. end note]13.4 User-defined conversions<strong>C#</strong> allows the pre-defined implicit and explicit conversions to be augmented by user-defined conversions.User-defined conversions are introduced by declaring conversion operators (§17.9.3) in class and structtypes.13.4.1 Permitted user-defined conversions<strong>C#</strong> permits only certain user-defined conversions to be declared. In particular, it is not possible to redefinean already existing implicit or explicit conversion. A class or struct is permitted to declare a conversion froma 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 §17.9.3.118

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!