13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 13 Conversions13.2.2 Explicit enumeration conversionsThe explicit enumeration conversions are:• From sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, or decimal toany enum-type.• From any enum-type to sbyte, byte, short, ushort, int, uint, long, ulong, char, float,double, or decimal.• From any enum-type to any other enum-type.An explicit enumeration conversion between two types is processed by treating any participating enum-typeas the underlying type of that enum-type, and then performing an implicit or explicit numeric conversionbetween the resulting types. [Example: For example, given an enum-type E with and underlying type of int,a conversion from E to byte is processed as an explicit numeric conversion (§13.2.1) from int to byte,and a conversion from byte to E is processed as an implicit numeric conversion (§13.1.2) from byte toint. end example]13.2.3 Explicit reference conversionsThe explicit reference conversions are:• From object to any reference-type.• From any class-type S to any class-type T, provided S is a base class of T.• From any class-type S to any interface-type T, provided S is not sealed and provided S does notimplement T.• From any interface-type S to any class-type T, provided T is not sealed or provided T implements S.• From any interface-type S to any interface-type T, provided S is not derived from T.• From an array-type S with an element type S E to an array-type T with an element type T E , provided allof the following are true:S and T differ only in element type. (In other words, S and T have the same number of dimensions.)Both S E and T E are reference-types.An explicit reference conversion exists from S E to T E .• From System.Array and the interfaces it implements, to any array-type.• From System.Delegate and the interfaces it implements, to any delegate-type.The explicit reference conversions are those conversions between reference-types that require run-timechecks 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 thedestination type by an implicit reference conversion (§13.1.4). If an explicit reference conversion fails, aSystem.InvalidCastException is thrown.Reference conversions, implicit or explicit, never change the referential identity of the object beingconverted. [Note: In other words, while a reference conversion may change the type of the reference, it neverchanges the type or value of the object being referred to. end note]13.2.4 Unboxing conversionsAn unboxing conversion permits an explicit conversion from type object or System.ValueType to anyvalue-type, or from any interface-type to any value-type that implements the interface-type. An unboxingoperation consists of first checking that the object instance is a boxed value of the given value-type, and then117

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

Saved successfully!

Ooh no, something went wrong!